When preparing a Customer onboarding workflow, an administrator at a growing distribution company needed to confirm which Customer fields held usable data before building saved searches, workflows, and integrations. For example, the Customer Status field stored an internal ID, while users saw a readable status name.
Script Sample
This scheduled script quickly checks the field type, stored value, and where relevant, display text, helping the admin configure automation correctly.
/**
* @NApiVersion 2 .1
* @NScriptType ScheduledScript
*/
define(['N/record', 'N/log'], (record, log) => {
const execute = () => {
// Load a Customer record.
const customer = record.load({
type: record.Type.CUSTOMER,
id: 123 // Replace with a valid Customer internal ID
});
// Customer fields to inspect.
const fieldIds = [
'companyname',
'email',
'entitystatus',
'isperson'
];
fieldIds.forEach((fieldId) => {
// Get the Field object to identify its type.
const field = customer.getField({
fieldId: fieldId
});
// Get the field's stored value.
const value = customer.getValue({
fieldId: fieldId
});
// Use the field type when logging the field information.
log.debug({
title: 'Customer Field: ' + fieldId,
details: 'Type: '+ field.type + ' | Value: ' + value
});
// Example: Select fields have an internal ID as their value.
if (field.type === 'select') {
const text = customer.getText({
fieldId: fieldId
});
log.debug({
title: fieldId + 'Display Text',
details: text
});
}
// Example: Checkbox fields return true or false.
if (field.type === 'checkbox') {
log.debug({
title: fieldId + 'Checkbox Result',
details: value ? 'Checked' : 'Not checked'
});
}
});
};
return {
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!