Get Country IDs and Country Names on SuiteScript

Scenario

This article describes how to get all countries defined in NetSuite via SuiteScript. This is possible by creating a Custom Record type and Custom Field with List/Record of Country. The sample script is also best executed in User Event: Before Load.

Solution

Create Custom Record Type

     1. Navigate to Customization > Lists Records & Fields > Record Types > New

  • NameEnter Script – Alternate Country List
  • ID: Enter _alternate_country

     2. ClickSave     3. Create New Field

  • Label: Enter Country Field
  • ID: Enter _country_list
  • Type: Select List/Record
  • List/Record: Select Country

     4. Click Save

Use code snippets below to get all countries and IDs:

require(['N/record'],

function(record) {‌

var rec = record.create({‌
type: 'customrecord_alternate_country',
isDynamic: true
});

var countryField = rec.getField({‌
fieldId: 'custrecord_country_list'
});

var countryOptions = countryField.getSelectOptions();

for(i in countryOptions ) {‌
var id=countryOptions[i].value;
var text = countryOptions[i].text;
};

});

Leave a comment

Your email address will not be published. Required fields are marked *