Suppose your company wants to review customer information before integrating it with an external CRM or performing data validation. Instead of manually checking each field in the NetSuite UI, you can use SuiteScript to automatically retrieve and log important customer fields along with their labels and values.
Sample Usage
/**
* @NApiVersion 2 .1
* @NScriptType ScheduledScript
*/
define(['N/record', 'N/log'], (record, log) => {
function execute() {
// Load an existing Customer record
var customer = record.load({
type: record.Type.CUSTOMER,
id: 123 // Replace with a valid Customer internal ID
});
// List of Customer field IDs to inspect
var fieldIds = [
'entityid',
'companyname',
'email',
'phone',
'comments'
];
// Loop through each field
fieldIds.forEach(function(fieldId) {
// Get the Field object
var field = customer.getField({
fieldId: fieldId
});
// Get the field value
var value = customer.getValue({
fieldId: fieldId
});
// Log the field's label, internal ID, and value
log.debug({
title: field.label,
details:
'Field ID: ' + field.id +
' | Value: ' + value
});
});
}
return {
execute: execute
};
});
- This script loads a Customer record and loops through a list of commonly used fields. For each field, it retrieves the Field object using getField(), obtains the field's current value using getValue(), and logs the field's display label (Field.label), internal ID (Field.id), and value.
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!