Scenario
You are the NetSuite administrator for your organization. You use the invoice record type for your invoices. This record type includes everything you need to manage your invoices, but it also includes some fields you don’t need. In the Item sublist on an invoice record, you don’t need to populate the Item field. This field appears as a column in the Item sublist, and you want to use a script to hide this column before an invoice is edited.
Customization Details
The customization for this use case includes:
- A user event script triggered on the beforeLoad entry point
Steps in this tutorial to complete this customization:
- Before You Begin
- Step 1: Write the Script
- Step 2: Create the Script Record
- Step 3: Deploy the Script
- Step 4: Test the Solution
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define([‘N/ui/serverWidget’, ‘N/log’], (serverWidget, log) => {
function beforeLoad(context) {
if (context.type === context.UserEventType.EDIT) {
hideColumnField(context.form, ‘item’, ‘item’);
}
}
function hideColumnField(formObj, sublistId, fieldId) {
try {
const formSublist = formObj.getSublist({
id: sublistId
});
if (formSublist) {
const formField = formSublist.getField({
id: fieldId
});
if (formField && typeof formField !== ‘undefined’ && formField !== null) {
formField.updateDisplayType({
displayType: serverWidget.FieldDisplayType.HIDDEN
});
}
}
} catch(error) {
log.error({
title: ‘Error occurred when hiding field’,
details: JSON.stringify({
sublistId: sublistId,
fieldId: fieldId
})
});
}
}
return {
beforeLoad: beforeLoad
};
});
Create the entry point function
This script is triggered on the beforeLoad entry point when an invoice record is loaded. The entry point function in this script determines if the record is being edited, and if so, it calls a helper function (that is also defined within the script).
Add the following function definition at the top of the define function:
function beforeLoad(context) {
if (context.type === context.UserEventType.EDIT) {
hideColumnField(context.form, 'item', 'item');
}
}