Dynamically Grab the NetSuite Account ID/URL in a SuiteScript

in , June 26th, 2024

When you require the NetSuite account ID or root URL in your SuiteScript, it is recommended that you do not use a hard-coded string. This allows the code to be ported to other environments quickly and easily.

Best practice: Do not hard code in NetSuite account IDs or root URLs for a NetSuite account!

Get NetSuite Account ID

let accountId = runtime.accountId;

Use the “runtime” module and “runtime.accountId” to grab the current NetSuite account ID.

Note: This value is read-only (for good reason).

Get NetSuite Account Root URL

let scheme = 'https://';
let host = url.resolveDomain({
    hostType: url.HostType.APPLICATION,
  1. The “scheme” should always be 'https://'
  2. Use the “url” module and “url.resolveDomain” to get the root URL as a string. (i.e., “<accountID>.app.netsuite.com”)
  3. Combine the “scheme” and “host” strings to define the root URL for the NetSuite Account.
Note: Other “root” domains for the NetSuite account are available using different “hostType"s. See the url module documentation for more details.

Author: Sam Gagliardi 

Got stuck on a step during this article?

We like to update our blogs and articles to make sure they help resolve any troubleshooting difficulties you are having. Sometimes, there is a related feature to enable or a field to fill out that we miss during the instructions. If this article didn't resolve the issue, please use the chat and let us know so that we can update the article!


Want to keep learning?

Our team of NetSuite professionals has written articles on a wide variety of NetSuite topics, from SuiteCommerce tips, to recommended NetSuite solutions, to available support services, and more! 

Your cart