- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 11:18 AM - edited 01-24-2023 11:23 AM
Hello,
I need a suggestion of how to do the following:
I imported a database of Countries and Cities. I need to create a Catalog Item (record producer... already created).
I have 2 tables where the data is stored (Country_Cities)
The table is something like this
Country | City |
USA | Arizona |
USA | Florida |
USA | Texas |
Italy | Rome |
Mexico | Guadalajara |
Mexico | Chiapas |
Ok.. so there are over 2000 records.
The record producer at the moment has 2 variables.. Countries and Cities
The cities will depend on the country they have selected previously.
The country variable is a LOOKUP SELECT BOX type. Using Unique Values only, so it can remove the duplicates.
Now... Should I use a UI Policyto look at the Country field, and find all the Cities for that particular field? and if so.. how can I do that? or another easier way?
At the end, this is what I would need.
If they Select USA in the country.. from the record producer..
The cities will be display (only USA cities).
Thank you all
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 12:22 PM
Hello @AngelP83 ,
Write the onchange client script on the countries field and pass the country name to Script include gliderecord the table and return the cities in cities field.
Please modify the below code
Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var country = g_form.getValue('country');
//Call script include
var ga = new GlideAjax('global.sampleUtils'); //Scriptincludename
ga.addParam('sysparm_name', 'getcitiesDetails'); //Method
ga.addParam('userId',country ); //Parameters
ga.getXMLAnswer(getResponse);
function getResponse(response){
console.log(response);
var res = JSON.parse(response);
console.log(res);
g_form.setValue('cityfieldname',res.cities);
}
}
Script include:
var sampleUtils = Class.create();
sampleUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getcityDetails: function(){
gs.addInfoMessage('script include triggered');
var userId = this.getParameter('userId');
obj = {};
var grSysUser = new GlideRecord('yourtable name');
grSysUser.addQuery('country',userId );
while(grSysUser.next)) {
obj.cities= grSysUser.getValue('city fieldname');
}
gs.addInfoMessage(obj+JSON.stringify(obj));
return JSON.stringify(obj);
},
type: 'sampleUtils'
});
OR
You can use Advance reference qualifier in the Cities and call this scritp inlcude direclty
javascript : new scriptinclduename.functionname(current.variables.countytry);
Thank you,
Omkar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 12:22 PM
Hello @AngelP83 ,
Write the onchange client script on the countries field and pass the country name to Script include gliderecord the table and return the cities in cities field.
Please modify the below code
Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var country = g_form.getValue('country');
//Call script include
var ga = new GlideAjax('global.sampleUtils'); //Scriptincludename
ga.addParam('sysparm_name', 'getcitiesDetails'); //Method
ga.addParam('userId',country ); //Parameters
ga.getXMLAnswer(getResponse);
function getResponse(response){
console.log(response);
var res = JSON.parse(response);
console.log(res);
g_form.setValue('cityfieldname',res.cities);
}
}
Script include:
var sampleUtils = Class.create();
sampleUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getcityDetails: function(){
gs.addInfoMessage('script include triggered');
var userId = this.getParameter('userId');
obj = {};
var grSysUser = new GlideRecord('yourtable name');
grSysUser.addQuery('country',userId );
while(grSysUser.next)) {
obj.cities= grSysUser.getValue('city fieldname');
}
gs.addInfoMessage(obj+JSON.stringify(obj));
return JSON.stringify(obj);
},
type: 'sampleUtils'
});
OR
You can use Advance reference qualifier in the Cities and call this scritp inlcude direclty
javascript : new scriptinclduename.functionname(current.variables.countytry);
Thank you,
Omkar