
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2022 07:37 PM
Can ServiceNow call an API to populate a drop-down list of locations in real-time from an external Azure hosted datasource holding location data? If so, what are the advantages/disadvantages of this?
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2022 02:29 AM
Here's a sample script.
Create a Service Catalog with 2 fields of Select box. The first field named "field" contains values "common" and "official". The second field will contain values obtained from REST API call.
onChange Client Script on field "field".
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
return;
}
var url = 'https://restcountries.com/v3.1/all';
try {
var request = new XMLHttpRequest();
request.open("GET", url, true);
request.setRequestHeader("Content-type", "application/json");
request.send();
request.onload = function() {
//var data = this.response;
var json = JSON.parse(this.response);
g_form.clearOptions('value');
for (var i = 0; i < json.length; i++) {
var v = json[i].name[newValue];
g_form.addOption('value', v, v);
}
};
} catch (e) {
alert(e.message);
}
}
Execution results. It takes about 2 seconds to fill the second field with values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2023 05:28 AM
Hi Hitoshi.
I am completely new to servicenow and trying to learn how to do exactly what you are showing. Do i have to create 2 select fields in UI Builder? If so - i managed to do that. I am stuck with attaching the onChange function to the field in UI builder. May i humbly ask you to guide please.
Thank you.