When working with SuiteScript, efficiency is key—especially when updating records. Instead of loading and saving an entire record, which consumes more governance units and slows down execution, NetSuite provides a more streamlined alternative: the submitFields() method.
The submitFields() method allows you to update and submit one or more body-level fields on an existing record without loading it into memory, significantly improving script performance. It also returns the internal ID of the updated record, making it a practical and resource-saving option for simple updates.
Using load() and save() Approach
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
*/
define(['N/record'], function(record) {
function onRequest(scriptContext) {
var rec = record.load({
type: record.Type.EMPLOYEE,
id:1903
})
rec.setValue({
fieldId: 'firstname',
value: 'Employee One'
})
rec.setValue({
fieldId: 'middlename',
value: ''
})
rec.setValue({
fieldId: 'lastname',
value: 'Save'
})
rec.save()
}
return {
onRequest: onRequest
};
});
Record after using load() and save() approach.
Using submitFields() Approach
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
*/
define(['N/record'], function(record) {
function onRequest(scriptContext) {
record.submitFields({
type: record.Type.EMPLOYEE,
id:1903,
values: {
firstname: 'Employee One',
middlename: '',
lastname: 'Submit Field'
},
options: {
enablesourcing: false, // disable sourcing
ignoreMandatory: true // disable mandatory validation
}
})
}
return {
onRequest: onRequest
};
});
Record after using submitFields() approach.
Choosing the right method for record updates can significantly improve your script’s efficiency and system performance. Use submitFields() wherever applicable!
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 records using SuiteScript? Feel free to share them here!