How to fetch reference field data in catalog client script or in script include

Ulka1
Tera Contributor

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

 

 

 

22 REPLIES 22

Hi Imran,
 
I tried this one, not working.

 

Hii @Ulka 

 

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);
}
}
}

 

find_real_file.png

find_real_file.png

 

find_real_file.png

 

find_real_file.png

 

Regards,

Imran Ahmad

 

Please Mark as Correct Answer :-

Please Mark Helpful:-

 

 

 

 

Thank You Imran.   I'll  check and let you know.

Ulka1
Tera Contributor

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.

Hii @Ulka 

 

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:-

find_real_file.png

 

find_real_file.png

 

 

find_real_file.png

 

 

Regards,

Imran Ahmad

 

 

 

Please Mark Helpful:-

If Worked Please mark correct answer:--