Execution Contexts

Execution contexts provide information about how or when a SuiteScript script or SuiteFlow workflow runs. For example, a script can be triggered because of an action in NetSuite, or because of an action in another context, such as a web services integration. You can use execution context filtering to make sure your scripts or workflows are triggered only when necessary. You can set them up to run only in certain contexts, which helps performance where the script or workflow is not required. You can also programatically check the execution context for a running script and use different logic depending on the context.

There are many execution contexts in NetSuite. The Scheduled context means a script or workflow was triggered because of a scheduled script. The Debugger context means the script was triggered using deployed or on-demand debugging in the SuiteScript Debugger. The following contexts provide more control over script and workflow processing:

Important:

The Web Services context from earlier releases is no longer available. It's now called SOAP Web Services.

For a full list of execution contexts, see Execution Context Types.

The execution context value for a script or workflow can change each time it runs, depending on how it was triggered. For example, if you have a context script deployed on customer records that uses the beforeLoad(context) entry point, editing a customer record in the NetSuite UI, triggers the beforeLoad(context) entry point and the context script runs. For this execution of the script, the execution context value is User Interface, because a UI event (editing a customer record) triggered the execution of the context script.

In the same way, when you edit a customer record using SOAP web services, the beforeLoad(context) entry point is triggered and the context script runs. For this execution of the script, the execution context value is SOAP web services since a SOAP web services event triggered the execution of the context script.

However, the beforeLoad(context) entry point can be triggered in other ways. This entry point is triggered right before a record loads, but the loading action doesn't need to happen in the NetSuite UI. If you create a scheduled script that runs daily and loads a record, the beforeLoad(context) entry point is triggered each time and the context script runs. For these executions of the context script, the execution context value is Scheduled, since an event from a scheduled script triggered the execution of the context script.

Execution context filtering works the same for scripts and workflows. The same values and defaults apply to both. By default, all contexts are selected except for Web Application and Web Store since scripts often don't need to be triggered in these contexts. If you want your script or workflow to be triggered in these contexts, make sure that you explicitly select them when you create your script deployment record or workflow.

When a record changes, you can use system notes to see the execution context that was used. For more information, see Execution Contexts in System Notes.

For more information about execution contexts in SuiteScript and SuiteFlow, see the following:

Execution Contexts in SuiteScript

For SuiteScript scripts, you set up execution context filtering on the Context Filtering tab when you create or edit a script deployment record:

Execution Context field on the script deployment record.

You can get execution context values in scripts using the runtime.executionContext property and the runtime.ContextType enum. The REST Web Services context is used with SuiteTalk Web Services. For more information, see Using the REST Web Services SuiteScript Execution Context.

Note:

Execution contexts are available only for client scripts and user event scripts.

You can use execution contexts in SuiteScript in two ways:

  • Set up execution context filtering on the Context Filtering tab — Select the contexts where you want your script to run. Your script won't process if it's triggered in a context that is not selected. For more information, see Using the Context Filtering Tab.

  • Determine the current execution context programmatically — You can check the context in which your script is running, compare the context to the available values in the runtime.ContextType enum, and take appropriate action. For more information, see runtime.executionContext.

Execution Contexts in SuiteFlow

For SuiteFlow workflows, you set execution context filtering in the Event Definition section when you create or edit a workflow:

Contexts field in a Suiteflow workflow.

For more information, see Execution Contexts and Workflows.

Related Topics

General Notices