When working with transactions, Administrators often need to confirm which custom forms are available to users on a record. This is especially useful when troubleshooting role permissions, form restrictions, transaction form setup, or unexpected form behavior on Sales Orders.
One practical way to inspect available form choices is by using SuiteScript’s getSelectOptions() method. This method allows you to check the options available in a select/dropdown field, such as the customform field on a Sales Order.
The script below demonstrates how a Scheduled Script can load a Sales Order, inspect the customform field, test different search filters, and log the Sales Order forms that are available from the dropdown.
SuiteScript Example
/**
* @NApiVersion 2.x
* @NScriptType ScheduledScript
*
*/
define(['N/record', 'N/log'], function(record, log) {
function execute(context) {
try {
/*
* Replace this with a valid Sales Order internal ID
* from your NetSuite account.
*/
var SALES_ORDER_ID = 00000;
/*
* The field we want to inspect.
*
* customform is the transaction form field.
* On a Sales Order, this represents the selected Sales Order form.
*/
var FIELD_ID_TO_CHECK = 'customform';
/*
* Filters to test against the customform dropdown.
*
* getSelectOptions() supports:
* - contains
* - startswith
* - is
*/
var filtersToTest = [
{
label: 'Forms containing "Standard"',
filter: 'Standard',
operator: 'contains'
},
{
label: 'Forms starting with "Sales"',
filter: 'Sales',
operator: 'startswith'
},
{
label: 'Forms exactly named "Standard Sales Order"',
filter: 'Standard Sales Order',
operator: 'is'
}
];
/*
* Load the Sales Order in dynamic mode.
*
* Important:
* getSelectOptions() on an N/record field requires dynamic mode.
*/
var salesOrder = record.load({
type: record.Type.SALES_ORDER,
id: SALES_ORDER_ID,
isDynamic: true
});
/*
* Get the customform field from the Sales Order.
*/
var formField = salesOrder.getField({
fieldId: FIELD_ID_TO_CHECK
});
/*
* If the field is not available on the record form,
* getField() may return null.
*/
if (!formField) {
log.audit({
title: 'Field Not Found',
details: 'The field "' + FIELD_ID_TO_CHECK + '" was not found on Sales Order ID ' + SALES_ORDER_ID
});
return;
}
/*
* Log the currently selected form value on the Sales Order.
*/
var currentFormValue = salesOrder.getValue({
fieldId: FIELD_ID_TO_CHECK
});
var currentFormText = salesOrder.getText({
fieldId: FIELD_ID_TO_CHECK
});
log.audit({
title: 'Current Sales Order Form',
details:
'Current Form Internal ID: ' + currentFormValue +
' | Current Form Name: ' + currentFormText
});
/*
* Object used to track unique form options found across all filters.
* This prevents duplicate logging if the same form appears
* in more than one filter result.
*/
var uniqueFormsFound = {};
/*
* Loop through each filter and call getSelectOptions().
*/
for (var i = 0; i < filtersToTest.length; i++) {
var test = filtersToTest[i];
log.audit({
title: 'Running getSelectOptions Test',
details:
test.label +
' | Filter: ' + test.filter +
' | Operator: ' + test.operator
});
/*
* Main method being demonstrated:
* getSelectOptions()
*
* This returns available dropdown options for the selected field.
*/
var options = formField.getSelectOptions({
filter: test.filter,
operator: test.operator
});
/*
* getSelectOptions() can return null if the field is not treated
* as a dropdown/select field in the current context.
*/
if (!options) {
log.audit({
title: 'No Options Returned',
details:
'No options were returned for filter "' +
test.filter +
'". The field may not be available as a dropdown in this context.'
});
continue;
}
log.audit({
title: 'Options Returned',
details:
test.label +
' | Number of options returned: ' +
options.length
});
/*
* Log each matching option.
*
* Each option usually contains:
* - value: internal ID of the option
* - text: label shown in the dropdown
*/
for (var x = 0; x < options.length; x++) {
var optionValue = options[x].value;
var optionText = options[x].text;
log.debug({
title: 'Matching Form Option',
details:
'Value/Internal ID: ' + optionValue +
' | Text/Form Name: ' + optionText
});
/*
* Save unique results for the final summary.
*/
uniqueFormsFound[optionValue] = optionText;
}
}
/*
* Count unique form options found across all filter tests.
*/
var totalUniqueForms = 0;
for (var formId in uniqueFormsFound) {
if (uniqueFormsFound.hasOwnProperty(formId)) {
totalUniqueForms++;
}
}
/*
* Final summary log.
*/
log.audit({
title: 'Form Option Audit Completed',
details:
'Sales Order ID: ' + SALES_ORDER_ID +
' | Field Checked: ' + FIELD_ID_TO_CHECK +
' | Unique Forms Found: ' + totalUniqueForms
});
} catch (e) {
/*
* Log unexpected script errors.
*/
log.error({
title: 'Scheduled Script Error',
details: e
});
}
}
return {
execute: execute
};
});
DISCLAIMER: The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. Oracle + NetSuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations.
Oracle + NetSuite Inc. does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. Oracle + NetSuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto.
Oracle + NetSuite Inc. shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code.
To know more about deploying SuiteScript, check these New to NetSuite Articles.
Do you have another way on how to automate your transactions using SuiteScript? Feel free to share them here!