Update fields on sales order and estimate records

This sample is a mass update script that updates fields on sales order and estimate records.

The conversion of this script from SuiteScript 1.0 to SuiteScript 2.1 includes the following:

SuiteScript 1.0 Script

SuiteScript 2.1 Script

                    function updateDepartment(rec_type, rec_id) {
    var transaction = nlapiLoadRecord(rec_type, rec_id);
    transaction.setFieldValue('department', nlapiGetContext().getSetting('SCRIPT', 'custscript_dept_update'));
    nlapiSubmitRecord(transaction, false, true);
} 

                  
                    /**
 *@NApiVersion 2.1
 *@NScriptType MassUpdateScript
 */

define(['N/record', 'N/runtime'], (record, runtime) => {
     function each(params) {
        const transaction = record.load({
            type: params.type,
            id: params.id
        });
        const scriptObj = runtime.getCurrentScript();
            
        const myDepartment = scriptObj.getParameter({
            name: 'custsript_dept_update'
        });

        transaction.setValue({
            fieldId: 'department',
            value: myDepartment
        });
        transaction.save({
            enableSourcing: false,
            ignoreMandatoryFields: true
        });
    }
        return {
            each: each
    };
}); 

                  

General Notices