Solution
define(['N/ui/serverWidget'],
/**
* @param{serverWidget} serverWidget
*/
(serverWidget) => {
/**
* Defines the function definition that is executed before record is loaded.
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {string} scriptContext.type - Trigger type; use values from the context.UserEventType enum
* @param {Form} scriptContext.form - Current form
* @param {ServletRequest} scriptContext.request - HTTP request information sent from the browser for a client action only.
* @since 2015.2
*/
const itemGroupForm = '149'; //JJ Expertec Estimate item group internal ID
const beforeLoad = (scriptContext) => {
try{
let currRec=scriptContext.newRecord;
let currentForm=currRec.getValue({
fieldId:'customform'
})
if ((scriptContext.type == scriptContext.UserEventType.CREATE||
scriptContext.type == scriptContext.UserEventType.EDIT)&& currentForm == itemGroupForm) {
// Get the form object
const form = scriptContext.form;
// Get the Items sublist
let sublist = form.getSublist({
id: "item"
});
// Add the custom button to the sublist
let showPdfButton = sublist.addButton({
id: "custpage_showpdf_button",
label: "Check All Show PDF",
functionName: "enableShowPdf"
});
}
}catch(e)
{
log.error("err@beforeLoad",e.message)
}
}
return {beforeLoad}
});