- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2022 01:03 AM
Hi All,
I want to auto populate requestor location details like city, street, country on the catalog form based on the requestor select in requestor field. There are three fields City, Country and Street on catalog form where i want to return these values.
Please help me with the script include and catalog client script code. I have idea about how we will do for single value like only City but not sure for multiple value.
Thanks in Advance!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2022 01:13 AM
Hi,
Please try something like below.
1. Create an onChange catalog client script on the requester variable.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('UserInformation');
ga.addParam('sysparm_name', "userInfo");
ga.addParam('sysparm_userID', g_form.getValue('requested_for_variable')); // replace with your variable name inside getValue.
ga.getXMLAnswer(function(answer){
if(answer){
var parser = JSON.parse(answer);
g_form.setValue('city_variable', parser.city); // replace with your variable name
g_form.setValue('country_variable', parser.country); // replace with your variable name
g_form.setValue('street_variable', parser.street); // replace with your variable name
}
});
//Type appropriate comment here, and begin script below
}
Create a script include:
var UserInformation = Class.create();
UserInformation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
userInfo: function(){
var obj = {};
var id = this.getParameter('sysparm_userID');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', id);
gr.query();
if(gr.next()){
obj['city'] = gr.getValue('city');
obj['country'] = gr.getValue('country');
obj['street'] = gr.getValue('street');
}
return JSON.stringify(obj);
},
type: 'UserInformation'
});
I hope that helps!
Regards,
Muhammad
Muhammad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2022 01:13 AM
Hi,
Please try something like below.
1. Create an onChange catalog client script on the requester variable.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('UserInformation');
ga.addParam('sysparm_name', "userInfo");
ga.addParam('sysparm_userID', g_form.getValue('requested_for_variable')); // replace with your variable name inside getValue.
ga.getXMLAnswer(function(answer){
if(answer){
var parser = JSON.parse(answer);
g_form.setValue('city_variable', parser.city); // replace with your variable name
g_form.setValue('country_variable', parser.country); // replace with your variable name
g_form.setValue('street_variable', parser.street); // replace with your variable name
}
});
//Type appropriate comment here, and begin script below
}
Create a script include:
var UserInformation = Class.create();
UserInformation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
userInfo: function(){
var obj = {};
var id = this.getParameter('sysparm_userID');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', id);
gr.query();
if(gr.next()){
obj['city'] = gr.getValue('city');
obj['country'] = gr.getValue('country');
obj['street'] = gr.getValue('street');
}
return JSON.stringify(obj);
},
type: 'UserInformation'
});
I hope that helps!
Regards,
Muhammad
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2022 02:11 AM
Should be simple enough
You can use onChange + GlideAjax and return multiple values from script include and then populate in catalog form variables
Get User Details based on the Logged in user/ User selected in Client Script
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader