When working with NetSuite, it’s important to ensure that your scripts are running in the correct environment, especially when dealing with sensitive operations. Here’s a guide on how to check if your NetSuite environment is Production using a script.
In the script, you can use the runtime module to determine the environment type. Here’s an example of how to do this:
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
*/
define([‘N/runtime’], function(runtime) {
function beforeLoad(context) {
var environment = runtime.envType;
if (environment === runtime.EnvType.PRODUCTION) {
log.debug(‘Environment Check’, ‘This is a Production environment.’);
// Proceed with your script logic for Production
} else {
log.debug(‘Environment Check’, ‘This is NOT a Production environment.’);
// Handle non-Production environment logic
}
}
return {
beforeLoad: beforeLoad
};
});
- runtime.envType: This property of the
runtimemodule returns the type of environment the script is running in. It can bePRODUCTION,SANDBOX,BETA, orRELEASE_PREVIEW. - log.debug: This function logs messages to the script execution log, which can be useful for debugging and verifying that the script is working as expected.
By following these steps, you can ensure that your script correctly identifies the environment type and proceeds accordingly. This is particularly useful for scripts that perform critical operations and need to behave differently based on the environment.