Get the Localization Context of an Employee Record

The following sample shows how to retrieve the localization context value for a record. The sample uses two different approaches depending on whether the record is loaded in the script. The subsidiary values are hard-coded. If you run this script in your account, be sure to replace the hard-coded values with valid values from your account.

Note:

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

          /**
 *@NApiVersion 2.x
 */
// This example calls the getContext() API with options recordType, recordId and  record.
require(['N/record', 'N/recordContext'],
    function(record, recordContext) {
        // Create record
        var employee = record.create({
            type : record.Type.EMPLOYEE,
            isDynamic: true
        })
        // Setup CA subsidiary          
        employee.setValue('subsidiary', 2); 
        employee.setValue('entityid', 'test_emp_' + Date.now())
        employeeId = employee.save()
         
        // getContext() with options recordType, recordId and contextTypes
        var employeeContext = recordContext.getContext({
            recordType : record.Type.EMPLOYEE,
            recordId: employeeId,
            contextTypes: [recordContext.ContextType.LOCALIZATION]
        })
        log.debug(employeeContext);  // expected log will list {"localization":["CA"]}

         // Change employee subsidiary to AU
         employee.setValue('subsidiary', 3); 

        // getContext() with options record and contextTypes
        var employeeContext = recordContext.getContext({
            record : employee,
            contextTypes: [recordContext.ContextType.LOCALIZATION]
        })
        log.debug(employeeContext);  // expected log will list {"localization":["AU"]}

        // Delete record
        record.delete({
            type : record.Type.EMPLOYEE,
            id: 1
        })
    }); 

        

General Notices