Search code examples
netsuiterestletrestlet-2.0netsuite-rest-api

Checking Execution Environments in NetSuite


I am trying to get the environment of the server: Production, Server, Beta via a restlet or some other way. I can get it with the runtime with: runtime.envType; but I do not know how to get the value from the server to compare. Here is an example, but don't know where this field would be coming from, here is what I'm trying to do below. What record type to load to GET in a http request.

function getServerEnvironment() {
    try {
        var response = http.get({
            url: '/app/site/hosting/restlet.nl?script=customscript_your_restlet_id&deploy=1'
        });

        return response.body; // Should return 'PROD', 'SAND', or 'BETA' based on server
    } catch (e) {
        log.error('Error Fetching Server Environment', e.message);
        return null;
    }
}

Solution

  • Any Netsuite script can use the N/runtime module to get the current environment.

    e.g. The code below runs in the console:

    require(['N/runtime'], runtime=>{
        console.log(runtime.envType);
    });
    

    If you are trying to get the current environment from an external system then you can include N/runtime in your define(['N/runtime',...], function (runtime, ...){ of your restlet or of any SS2.x script type.