How to query the REST API for states/provinces/cou...
# ask-stanley-ai
c
How to query the REST API for states/provinces/counties
c
AI generated answer (using internal Slack threads):
To query the REST API for states/provinces/counties in NetSuite, you can use the SuiteScript API's
search.create
method. Here is an example of how to do this:
Copy code
javascript
var stateSearchObj = search.create({
   type: "state",
   filters:
   [
      ["country","anyof","CA"]
   ],
   columns:
   [
      search.createColumn({
         name: "id",
         sort: search.Sort.ASC,
         label: "Id"
      }),
      search.createColumn({name: "fullname", label: "Full Name"}),
      search.createColumn({name: "shortname", label: "Short Name"}),
      search.createColumn({name: "country", label: "Country"}),
      search.createColumn({name: "inactive", label: "Inactive"})
   ]
});
var searchResultCount = stateSearchObj.runPaged().count;
log.debug("stateSearchObj result count",searchResultCount);
stateSearchObj.run().each(function(result){
   // .run().each has a limit of 4,000 results
   return true;
});
In this example, a search is created for the "state" type. The filter is set to return only states in Canada ("CA"). The columns to be returned are the id, full name, short name, country, and whether the state is inactive. The search is then run and the results are logged. Please note that the
.run().each
function has a limit of 4,000 results. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.819580078
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.816040039
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.815673828
Please provide your feedback on this answer.
Thank you for your feedback