How to fetch reference field data in catalog client script or in script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 12:28 AM
Hi Expertise,
I need to fetch reference field(like caller) data such as location which is stored in sys_user table and then I have to use this location in catalog client script. so please could anyone suggest me how to achieve this one. I tried getReference method but it is not working.
Awaiting for your response.
Thank You,
Ulka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 01:53 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 02:27 AM
Hii
Try this tested code I have tested in my PDI and its working fine:--
Sending you the Screen short it help you for sure and Also check in you client script the right variable name is selected like:caller_id.
Copy and paste below code and change the field name as per you requirement:-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var caller = g_form.getReference("requested_by",callback);
function callback(caller){
if(caller.location == "8226baa4ac1d55eb40eb653c02649519"){
g_form.setValue('email',caller.email);
}
}
}
Regards,
Imran Ahmad
Please Mark as Correct Answer :-
Please Mark Helpful:-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 03:11 AM
Thank You Imran. I'll check and let you know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 04:01 AM
No, Imran. Not getting result, field value is not getting set. Is there any other solution like script include. If you have some idea then please help me.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 05:10 AM
Hii
Second way to achieve this requirement copy and paste the code and change the field value as per your requirement
if this way not worked in your instance then send the screen shot of client script, Script includes and item form:-
Script includes copy and paste:-
var ReturnLocation = Class.create();
ReturnLocation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
UserLocation: function(){
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id",this.getParameter("sysparm_ID"));
gr.query();
if(gr.next()){
return gr.location.toString();
}
},
type: 'ReturnLocation'
});
Client Script copy and paste :-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax("ReturnLocation");
ga.addParam("sysparm_name","UserLocation");
ga.addParam("sysparm_ID",newValue);
ga.getXML(callback);
function callback(response){
var location = response.responseXML.documentElement.getAttribute("answer");
if(location == "8226baa4ac1d55eb40eb653c02649519"){
g_form.setValue("email","Code is working fine");
}
}
}
Attaching the tested screen shot below please check:-
Regards,
Imran Ahmad
Please Mark Helpful:-
If Worked Please mark correct answer:--