How can a script detect if it is running in a sand...
# ask-stanley-ai
s
How can a script detect if it is running in a sandbox?
c
AI generated answer (using internal Slack threads):
In SuiteScript, you can use the
runtime
module to detect if your script is running in a sandbox environment. The
runtime.envType
property will return 'SANDBOX' if the script is running in a sandbox. However, this property does not distinguish between different sandboxes if you have more than one. To identify a specific sandbox, you can use the
runtime.accountId
property. This property will return a unique identifier for the account, which includes a suffix for the sandbox. For example, if you are in Sandbox 1, it might return '123456_SB1', and for Sandbox 2, it might return '123456_SB2'. Here is a sample code snippet:
Copy code
javascript
var runtime = require('N/runtime');
var environment = runtime.envType;
var accountId = runtime.accountId;

if (environment === 'SANDBOX') {
    if (accountId.endsWith('_SB1')) {
        // Code for Sandbox 1
    } else if (accountId.endsWith('_SB2')) {
        // Code for Sandbox 2
    }
}
Please note that the suffixes '_SB1' and '_SB2' are just examples. The actual suffixes may vary depending on your NetSuite setup. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
a
For SuiteScript 1.0, use nlapiGetContext().environment, and it will return "SANDBOX".
👍 1
c
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.840657532
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.824641585
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.81959188
Please provide your feedback on this answer.
a
For SuiteScript 2.x, use the Stanley AI answer. I think 1.0 also has a way of determining the full account number such as ends in _SB1 or _SB2, etc.