How to Use SuiteScript to Get NetSuite Country Names and Internal IDs

in , February 13th, 2025

Many times, when creating an address form that requires country input, a developer may become stuck without an easy path forward. Getting country internal IDs in NetSuite can be a bit tricky, so here is a neat trick!

SuiteScript Solution to Get NetSuite Country Names and Internal IDs

Using the N/query module, a query can be run directly against the Country table in NetSuite, which is not normally exposed to Saved Searches in the UI or the N/search module. This allows the developer to generate a dynamic list that matches the list internal to NetSuite, respecting the company-specific settings in effect. The following query gives both the name and the unique key (which serves as the internal ID), which could then be used to populate a selection list.

const countries = N_query.runSuiteQL({
    query: "SELECT name, uniquekey FROM Country",
}).results.map(element => {
    return {
        value: element.values[1],
        text: element.values[0]
    };
});

You can also copy the source directly from a GitHub Gist right here.

Author: Steve Linn


Got stuck on a step in 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 this article!

Oracle NetSuite Alliance Partner & Commerce Partner

If you have general questions about SuiteScript or more specific questions about how our team can support your business, feel free to contact us anytime. Anchor Group is a certified Oracle NetSuite Alliance Partner and Commerce Partner equipped to handle all kinds of NetSuite and SuiteCommerce projects, large or small!

 
 

Want to keep learning?

Our team of NetSuite and ecommerce professionals has written articles on a wide variety of topics, from step-by-step tutorials, to solution recommendations, available support services, and more!

Your cart