Prerequisite is a client script deployed on the sales order record. This script is deployed to execute for all roles, however it should not execute certain parts when the sales order is accessed from the web store.
The nlobjContext object encapsulates script execution context at run time. It exposes the method getExecutionContext(), which returns context information about what triggered the current script. However, for client SuiteScript is will always return 'userinterface'. In order to overcome this limitation and correctly identify that the client script is triggered from the web store, the getExecutionContext() method call can be delegated to a Suitelet.
The client script can call the Suitelet by nlapiRequestURL(url). In order to identify the url, nlapiResolveURL() can be used by setting the type to 'SUITELET' and specifying the script and deployment ids.
var url = nlapiResolveURL('SUITELET', 'customscript1', 'customdeploy1'); var result = nlapiRequestURL(url); nlapiLogExecution('DEBUG', 'execution context', result.getBody());
In order for the Suitelet to obtain the execution context, it has to first get the context object - can be done by using nlapiGetContext(). On this object getExecutionContext() can be called. In order to send the response to the client script the response object's write() method can be used. The client script can read the response by using the getBody() method of the nlobjResponse object.
var context = nlapiGetContext(); var executionContext = context.getExecutionContext(); response.write(executionContext);