Using the REST Web Services SuiteScript Execution Context

Execution contexts provide information about how or when a script or workflow is triggered to execute. For example, a script can be triggered in response to an action in the NetSuite application or an action occurring in another context, such as a web services integration. You can use execution context filtering to ensure that your scripts or workflows are triggered only when necessary. This filtering can improve performance in contexts where the scripts or workflows are not required.

For NetSuite user event and client scripts, you can set up execution context filtering to control the contexts in which these scripts can run. You can set up execution context filtering in the Execution Context field on the Context Filtering subtab of the Script Deployment record. For information about script deployment, see Methods of Deploying a Script. For more information about execution contexts in general, see Execution Contexts and runtime.executionContext.

If a script has its execution context set to REST web services, the script only executes if it is triggered through a REST web services request.

For example, you can deploy a script similar to the following on customer records. In this example, the beforeSubmit script is only executed on the record if the request is triggered through REST web services.

          define(['N/record', 'N/runtime'],
         function(record, runtime) {
        function beforeSubmit(context) {
            log.debug("Before submit of " + context.newRecord.type);
            var executionContext = runtime.executionContext;
            var isRestWs = (runtime.ContextType.REST_WEBSERVICES === executionContext);
            log.debug("Is originating from REST WS: " + isRestWs);
        }
    }) 

        

After running the script, you can see its execution context in the script execution log. See Using the Script Execution Log Tab. You can also find information about the execution context in the system notes of a record. See Viewing System Notes on a Record.

Related Topics

The REST API Browser
NetSuite Record Structure
Using CRUD Operations on Custom Records, Custom Lists, and Custom Transactions v1
Creating a Record Instance
Getting a Record Instance
Updating a Record Instance
Using the Upsert Operation
Deleting a Record Instance
Accessing Subresources in REST Web Services
Using External IDs
Using Datetime Fields
Executing Record Actions
Transforming Records
Working with the Pricing Sublist on Item Records

General Notices