N/util Module Script Sample

The following script sample demonstrates how to use the features of the N/util module.

Set Fields on a Sales Order Record Using the util.each Iterator

The following sample creates a sales order record. It uses the util.each(iterable, callback) method to set record fields based on the values in an iterable object. Be sure to replace hard-coded values (such as record IDs) with valid values from your NetSuite account.


This sample script uses the require function so that you can copy it into the SuiteScript Debugger and test it. You must use the define function in an entry point script (the script you attach to a script record and deploy). For more information, see SuiteScript 2.x Script Basics and SuiteScript 2.x Script Types.

 * @NApiVersion 2.x

require(['N/record'], function(record){
    // Create a sales order
    var rec = record.create({
        type: 'salesorder', 
        isDynamic: true
        fieldId: 'entity',
        value: 107

    // Set up an object containing an item's internal ID and the corresponding quantity
    var itemList = {
        39: 5, 
        38: 1

    // Iterate through the object and set the key-value pairs on the record
    util.each(itemList, function(quantity, itemId){     // (5, 39) and (1, 38)

    var id = rec.save();


General Notices