NetSuite / SuiteScript: Get Configuration Information via a RESTlet

Published on July 25, 2019

Here's a follow-up to this post that provides a RESTlet that provides additional information.

Here's an interesting RESTlet that I recently wrote that can be used to provide NetSuite account configuration information to external systems.

The RESTlet uses the SuiteScript 2.0 runtime module ("N/runtime") and provides the configuration information as a JSON-encoded response. Some of the information that is provided includes the environment type, NetSuite version, processor count, queue count, and more. This information can be helpful if you are troubleshooting a problem for a client.

Here's an example of the RESTlet's response:

{
  "accountId": "NSPRTR2311311",
  "envType": "PRODUCTION",
  "executionContext": "RESTLET",
  "processorCount": 15,
  "queueCount": 15,
  "version": "2019.2",
  "currentScript": {
    "id": "customscript_runtime_info_api",
    "deploymentId": "customdeploy_runtime_info_api",
    "logLevel": "DEBUG",
    "bundleIds": []
  },
  "currentSession": {},
  "currentUser": {
    "id": -5,
    "name": "Tim Dietrich",
    "email": "timdietrich@ironforge.software",
    "location": 0,
    "department": 7,
    "role": 2,
    "roleId": "administrator",
    "roleCenter": "BASIC",
    "subsidiary": 1
  }
}

Here's the script:

/**
* @NApiVersion 2.x
* @NScriptType Restlet
* @NModuleScope Public
*/

/* 

--------------------------------------------------------------------------------
Script Information
--------------------------------------------------------------------------------

Name:
Runtime Info API

ID:
_runtime_info_api

Description
Provides a Web API for getting runtime information.


--------------------------------------------------------------------------------
Developer(s)
--------------------------------------------------------------------------------

TD:
• Tim Dietrich
• timdietrich@me.com


--------------------------------------------------------------------------------
History
--------------------------------------------------------------------------------

20190712 - TD
• Initial version.
		
*/



var 	
	runtime;


define( [ 'N/runtime' ], main );


function main( runtimeModule ) {

	runtime = runtimeModule;
	
    return {
        get: getProcess
    }

}


function getProcess( request ) {

	return runtimeInfoGet();
	
}  


function runtimeInfoGet() {

	// Returns all information available from the runtime module.
		
	var runtimeInfo = {}
	runtimeInfo.accountId = runtime.accountId;
	runtimeInfo.envType = runtime.envType;
	runtimeInfo.executionContext = runtime.executionContext;
	runtimeInfo.processorCount = runtime.processorCount;
	runtimeInfo.queueCount = runtime.queueCount;
	runtimeInfo.version = runtime.version;	
	runtimeInfo.currentScript = runtime.getCurrentScript();
	runtimeInfo.currentSession = runtime.getCurrentSession();
	runtimeInfo.currentUser = runtime.getCurrentUser();		
	return runtimeInfo;
	
}

If you'd like to filter the information that is returned, simply adjust the "runtimeInfoGet" function. For example, you might want to exclude the Account ID or user information.

Feel free to reach out to me if you have any comments or questions about the script.