JBL
04/16/2021, 4:09 AMmichoel
04/16/2021, 5:47 AMmichoel
04/16/2021, 5:53 AM// ==UserScript==
// @name Prettify staging record JSON payload
// @namespace <http://tampermonkey.net/>
// @version 0.1
// @description Display the JSON payload field for "Staging" Custom Records as a prettified JSON tree
// @author Michoel Chaikin <michoel.chaikin@carsales.com.au>
// @match https://*.<http://app.netsuite.com/app/common/custom/custrecordentry.nl?rectype=187*|app.netsuite.com/app/common/custom/custrecordentry.nl?rectype=187*>
// @require <https://code.jquery.com/jquery-3.3.1.min.js>
// @require <https://unpkg.com/jquery.json-viewer@1.4.0/json-viewer/jquery.json-viewer.js>
// @resource JSONViewerCSS <https://unpkg.com/jquery.json-viewer@1.4.0/json-viewer/jquery.json-viewer.css>
// @grant GM_addStyle
// @grant GM_getResourceText
// ==/UserScript==
/* global nlapiGetFieldValue, nlapiLookupField, nlapiGetRecordType, nlapiGetRecordId */
(function ($, undefined) {
'use strict';
const jsonViewerCSS = GM_getResourceText("JSONViewerCSS");
GM_addStyle(jsonViewerCSS);
$(function () {
// Don't run if record is in Edit mode
if(nlapiGetFieldValue('name')) {
return;
}
const jsonPayload = nlapiLookupField(nlapiGetRecordType(), nlapiGetRecordId(), 'custrecord_fsg_st_json');
$('#custrecord_fsg_st_json_fs_lbl_uir_label')
.next()
.jsonViewer(JSON.parse(jsonPayload), { collapsed: true, rootCollapsable: false });
})
})(window.jQuery.noConflict(true));