ANS-1039 · SUITESCRIPT DEVELOPMENT
How to Identify a Transaction’s Origin (e.g., Webstore) in NetSuite SuiteScript?
Learn how to programmatically identify if a NetSuite transaction was created via the webstore using SuiteScript 2.x, enhancing custom logic and automation.
Short answer
To determine if a NetSuite transaction originated from a webstore, use SuiteScript 2.x's `runtime.executionContext`. This function returns the context in which the script is currently executing. Check if the returned value is equal to 'webstore' to confirm its origin, enabling specific logic for web-generated transactions.
Scenario
NetSuite users often need to programmatically identify the origin of a transaction, such as determining if it was created via the NetSuite webstore. This distinction is vital for applying specific business rules, custom workflows, or data validations that should only trigger for web-generated orders.
Solution
To identify if a NetSuite transaction originated from a webstore, implement a SuiteScript 2.x script that utilizes the N/runtime module. This method is recommended for accurately determining the transaction's origin, rather than relying solely on a 'source' field.
Retrieve the current script's execution context using
runtime.executionContext.Evaluate if the returned context value is equal to 'webstore'.If
runtime.executionContextreturns 'webstore', it indicates that the transaction was initiated through the NetSuite webstore.Example:
javascriptvar currentExecutionContext = runtime.executionContext;if (currentExecutionContext === 'webstore') { // Logic for webstore-originated transactions}Expert NetSuite Support
Need help with this NetSuite issue?
SuiteScript Development consulting and configuration support
