Hide Body Fields and Sublist Columns on Transaction Forms
This script runs when a transaction loads in the UI (Create/Edit/View). It can hide body (header) fields, hide sublist columns, and optionally restrict behavior by role and transaction form.
Scenario
You want to control field visibility on transaction forms by configuration. The script can hide body fields such as memo or custbody_*, hide sublist columns such as custcol_* or taxdetailsreference, and apply only to selected roles and forms.
Customization Details
The customization for this use case includes:
-
A user event script triggered on the
beforeLoadentry point. -
Deployment parameters to control roles, forms, body fields, sublists, and sublist fields.
Steps in this tutorial to complete this customization:
Before You Begin
Use the following internal IDs during setup:
|
Item |
Where to Find It |
|---|---|
|
Role internal ID |
Go to Setup > Users/Roles > Manage Roles. Then, click a role and check URL id=#### (or use Show Internal IDs). |
|
Transaction form internal ID |
Go to Customization > Forms > Transaction Forms. Then, edit form and check URL id=###. |
|
Body and sublist field IDs |
Go to Customization > Lists, Records, & Fields for custom fields |
|
Standard field IDs |
Confirm through Customize Form (if field IDs are shown), SuiteScript Records Browser (NetSuite Help), or account field metadata. |
|
Sublist IDs |
Common values: |
Step 1: Write the Script
This sample uses SuiteScript 2.1 and a User Event Script.
Script Summary
|
Field |
Value |
|---|---|
|
Script Type |
User Event Script |
|
API Version |
2.1 |
|
Module Used |
|
|
Entry Point |
|
For more information about script types and entry points, see SuiteScript 2.1 Script Types.
The Complete Script
This tutorial includes the complete script. The complete script is provided below so that you can copy and paste it into your text editor and save the script as a .js file (for example, <add an example filename - start with the script type abbreviation, such as 'ue_this_script;>.js).
This tutorial script uses the define function, which is required for an entry point script (a script you attach to a script record and deploy). You must use the require function if you want to copy the script into the SuiteScript Debugger and test it. For more information, see SuiteScript Debugger.
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define(['N/runtime'], (runtime) => {
/*
* Parameter constraints accommodated:
* - Labels <= 25 chars (you choose labels in UI; suggestions below)
* - IDs <= 30 chars (the IDs below are <= 30)
*
* Create these PARAMETERS on the Script record (then set per deployment):
*
* 1) Roles (optional)
* ID: custscript_hf_roles
* Example: 1019,1050
*
* 2) Forms (optional)
* ID: custscript_hf_forms
* Example: 123,456
*
* 3) Body Flds (optional)
* ID: custscript_hf_body
* Example: memo,custbody_myfield
*
* 4) Sublists (optional)
* ID: custscript_hf_sublists
* Example: item,expense
*
* 5) Sublist Flds (optional)
* ID: custscript_hf_subflds
* Example: taxdetailsreference,custcol_mycol
*/
const P_ROLES = 'custscript_hf_roles';
const P_FORMS = 'custscript_hf_forms';
const P_BODY = 'custscript_hf_body';
const P_SUBLSTS = 'custscript_hf_sublists';
const P_SUBFLDS = 'custscript_hf_subflds';
const DEFAULT_SUBLISTS = ['item', 'expense', 'line', 'apply', 'credit', 'payment', 'billing'];
const parseCsv = (val) =>
String(val || '')
.split(',')
.map(s => s.trim())
.filter(Boolean);
const parseCsvNums = (val) =>
parseCsv(val)
.map(v => Number(v))
.filter(n => Number.isFinite(n));
const beforeLoad = (context) => {
// UI only
const allowedTypes = [context.UserEventType.CREATE, context.UserEventType.EDIT, context.UserEventType.VIEW];
if (!allowedTypes.includes(context.type)) return;
const script = runtime.getCurrentScript();
// Role filter (optional)
const allowedRoles = parseCsvNums(script.getParameter({ name: P_ROLES }));
if (allowedRoles.length) {
const currentRole = Number(runtime.getCurrentUser().role);
if (!allowedRoles.includes(currentRole)) return;
}
// Form filter (optional) - transactions typically use "customform"
const allowedForms = parseCsvNums(script.getParameter({ name: P_FORMS }));
if (allowedForms.length) {
const formId = Number(context.newRecord.getValue({ fieldId: 'customform' }));
if (!allowedForms.includes(formId)) return;
}
const form = context.form;
// Hide body fields
const bodyFieldIds = parseCsv(script.getParameter({ name: P_BODY }));
bodyFieldIds.forEach((fieldId) => {
try {
const fld = form.getField({ id: fieldId });
if (fld) fld.updateDisplayType({ displayType: 'HIDDEN' });
} catch (e) {
// ignore
}
});
// Hide sublist columns
const sublistFieldIds = parseCsv(script.getParameter({ name: P_SUBFLDS }));
if (!sublistFieldIds.length) return;
const configuredSublists = parseCsv(script.getParameter({ name: P_SUBLSTS }));
const sublistsToCheck = configuredSublists.length ? configuredSublists : DEFAULT_SUBLISTS;
sublistsToCheck.forEach((sublistId) => {
let sublist;
try {
sublist = form.getSublist({ id: sublistId });
} catch (e) {
return;
}
if (!sublist) return;
sublistFieldIds.forEach((fieldId) => {
try {
const fld = sublist.getField({ id: fieldId });
if (fld) fld.updateDisplayType({ displayType: 'HIDDEN' });
} catch (e) {
// ignore
}
});
});
};
return { beforeLoad };
});
Step 2: Create the Script Record
You can upload the script file to the File Cabinet and create a script record for it.
For more information about creating script records, see Creating a Script Record.
To create the script record:
-
Upload your script to the NetSuite File Cabinet.
-
Go to Customization > Scripting > Scripts > New.
-
Select User Event Script and then select the uploaded script file.
-
Open the Parameters tab and add the following parameters:
Parameter
Label
ID
Type
Description/ Help
Allowed Role IDs (optional)
Role IDs
custscript_hf_roles Free-form text
List of role internal IDs, for example 1019,1050. Blank = all roles.
Allowed Form IDs (optional)
Transaction Form IDs
custscript_hf_forms Free-form text
List of transaction form internal IDs, for example 123,456. Blank = all forms.
Body Field IDs to hide (optional)
Body Field IDs to hide
custscript_hf_body Free-form text
List of body field IDs, for example
memo,custbody_myfield.Sublist IDs to target (optional)
Sublist IDs to target
custscript_hf_sublists Free-form text
List of sublist IDs, for example
item,expense. Blank = script uses defaults.Sublist Field IDs to hide (optional)
Column Field IDs to hide
custscript_hf_subflds Free-form text
List of sublist field IDs, for example
taxdetailsreference,.custcol_mycol
NetSuite does not always auto-add custscript for you. Behavior can vary by UI/version, and in many accounts, you must enter the full script parameter ID exactly as you want it stored.
Step 3: Deploy the Script
After you create the script record for your script, you can create a script deployment record for it. A script deployment record determines how, when, and for whom the script runs.
For more information about script deployment records, see Script Deployment.
To deploy the script:
-
On the script record, click Deploy Script.
-
Set the deployment values:
Field
Value
Status
"Testing" (initially), then "Released" when validated
Applies To (Record Type)
Transaction type, for example "Vendor Bill", "Invoice", "Sales Order"
Execute As Role
"Default" (if you don't have a reason to change this value)
Event Behavior
Script runs in
beforeLoad. Deployment must be active. -
Click Save.
-
Open the deployment record and set the parameters as needed.
Example Deployment Values
-
custscript_hf_roles= "1019" -
custscript_hf_forms= "123" -
custscript_hf_body= (leave blank if none) -
custscript_hf_sublists= "item,expense" -
custscript_hf_subflds= "taxdetailsreference"
Notes:
-
Multiple values are comma-separated, for example "1019", "1050".
-
If "Allowed Role IDs" is blank, it applies to all roles.
-
If "Allowed Form IDs" is blank, it applies to all forms of that transaction type.
Step 4: Test the Solution
After you create the script record and deploy your script, you can test your solution.
To test your solution:
-
Set the Deployment Status field to "Testing".
-
Log in as a user with the target role.
-
Open a transaction using the target form.
-
Verify the configured body fields are hidden.
-
Verify the configured sublist columns are hidden.
-
Confirm the script doesn't affect other forms or roles when restricted.
-
Set Deployment Status field to "Released" when confirmed.
Related Topics
- SuiteCloud Customization Tutorials
- Add Custom Button to Run a Suitelet
- Calculate Commission on Sales Orders
- Copy a Value to the Item Column
- Disable Tax Fields
- Hide a Column in a Sublist
- Populate Item Substitution
- Set a Default Posting Period in a Custom Field
- Set Purchase Order Exchange Rate
- Set the Item Amount to Zero for Marketing Orders
- Set Default Values in a Sublist
- Track Customer Deposit Balances
- Validate Order on Entry