- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2022 05:00 AM
I have created a custom table with above three fields(city, state and Country) and I have given a reference to cmn_location table for City. So,When user select a city,based on selection of city its corresponding state and country must be auto-populated using any scripting.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2022 05:05 AM
Hi Tejas,
Refer this client script and script include to fulfill your requirement
https://community.servicenow.com/community?id=community_question&sys_id=08c24761dbd8dbc01dcaf3231f9619f3
Kindly Mark correct and helpful if its applicable

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2022 05:05 AM
Hi Tejas,
Refer this client script and script include to fulfill your requirement
https://community.servicenow.com/community?id=community_question&sys_id=08c24761dbd8dbc01dcaf3231f9619f3
Kindly Mark correct and helpful if its applicable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2022 05:27 AM
can we used scratchpad variable with Client script instead of using script include?
if yes then How?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2022 05:29 AM
g_scratchpad we can use in Onload client script it's best practice, but we need onchnage client script here. So its better to go with GlideAjax

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2022 05:42 AM
Please check below script working for me
Client Script // onChange State
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax("MyFavoritesAjax");
ga.addParam("sysparm_name", "getFavorites");
ga.addParam("sysparm_caller", g_form.getValue('u_city'));
ga.getXML(ajaxResponse);
function ajaxResponse(serverResponse) {
var favorites = serverResponse.responseXML.getElementsByTagName("favorite");
for (var i = 0; i < favorites.length; i++) {
var name = favorites[i].getAttribute("name");
var value = favorites[i].getAttribute("value");
alert ("value" + value);
if (name == 'state') {
g_form.setValue('u_state1', value);
}
if (name == 'country') {
g_form.setValue('u_country1', value);
}
}
}
}
Script Include :
var MyFavoritesAjax = Class.create();
MyFavoritesAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getFavorites: function() {
var id = this.getParameter('sysparm_caller'); // to get parameter from client side
gs.info(' chetan callidis' + id);
var loc = new GlideRecord('cmn_location');
loc.addQuery('sys_id', id);
loc.query();
if (loc.next()) {
gs.info("Chetan State : " + loc.state);
this._addFavorite("state", loc.state);
this._addFavorite("country", loc.country);
}
},
_addFavorite: function(name,value) {
var favs = this.newItem("favorite");
favs.setAttribute("name", name);
favs.setAttribute("value", value);
},
type: "MyFavoritesAjax"
});
Result :
Kindly mark helpful if works for you