ANS-1815 · SUITESCRIPT DEVELOPMENT
How to Detect NetSuite Environment and Generate URLs in SuiteScript?
Learn the standard SuiteScript 2.x methods for identifying the NetSuite environment and constructing dynamic URLs.
Short answer
NetSuite environments can be detected using N/runtime.envType in SuiteScript 2.x. For URL generation, the N/url module is the standard approach. Custom libraries like ITR_GeneralLibrary.js with functions such as getBaseNetsuiteURL() may also be used to create environment-specific URLs.
Scenario
Developers often need to programmatically determine the current NetSuite environment (e.g., Sandbox, Production) to ensure scripts behave correctly across different instances. Additionally, generating dynamic URLs within SuiteScript is a common requirement for linking to records, pages, or custom scripts, often needing to adapt based on the environment.
Solution
NetSuite developers can programmatically handle environment detection and URL generation within SuiteScript.
Environment Detection:
To determine the current NetSuite environment in SuiteScript 2.x, the N/runtime module's envType property is utilized.
javascriptN/runtime.envTypeURL Generation:
For generating URLs, standard SuiteScript 2.x applications typically use the N/url module. Custom utility methods may also be implemented to generate URLs based on the environment. An example of such a custom method is getBaseNetsuiteURL(), which might be located in a custom library such as ITR_GeneralLibrary.js within the erpguru folder.
javascriptgetBaseNetsuiteURL() in ITR_GeneralLibrary.js under the erpguru FolderExpert NetSuite Support
Need help with this NetSuite issue?
SuiteScript Development consulting and configuration support
