Set the sales rep on the record in a workflow

This sample is a user event script that sets the sales rep on the record in a workflow. To get a new record in SuiteScript 2.x, place this code in a user event script's beforeLoad, beforeSubmit, or afterSubmit entry point. For this example, the beforeLoad entry point is used.

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 changeSalesRep() {
    nlapiGetNewRecord().setFieldValue('salesrep', nlapiGetContext().getSetting('SCRIPT', 'custscript_salesrep'));
} 

                  
                    /*
 * @NApiVersion 2.1
 * @NScriptType UserEventScript
 */

define (['N/currentRecord', 'N/runtime'], (currentRecord, runtime) => {
    function changeSalesRep(context) {
        const myRecord = context.newRecord;
        const scriptObj = runtime.getCurrentScript();
        const myScriptParam = scriptObj.getParameter({
            name: 'custscript_salesrep'
        });
    
        myRecord.setValue({
           fieldId: 'salesrep',
           value: myScriptParam
        });
    }
    
    return {
        beforeLoad: changeSalesRep
    };
}); 

                  

General Notices