how to get original value instead of sys id
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2020 04:01 AM
Hi,
I am using getReference on catalog client script and also getting value fine but one of value i am getting is sys id but i want its text value ie display value not sys id . i use getDisplayValue() or display box but nothing is working
code look like..
var caller = g_form.getReference("variables.user",callback);
function callback(caller){
var location = caller.location;// getting sys id
// Need to change this sys id into display value format
g_form.setValue("variables.location",location);
}
Thanks in advance

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2020 04:15 AM
hi,
Dotwalking does not work in client script.
Using g_form.getReference will only get you records to 1 level. If that level contains data, you can show it. But if that level contains sys_ids then you need to use gliderecord again based on sys_id and get the value.
Or simply use a SI instead of g_form.getReference and return the value accordingly.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2020 04:16 AM
Hi Vikram,
You need can follow link that takes you to a blog that helps you use of getReferenceAdvanced
A kind of double dot-walk which should help suffice your need.
Else you can also look for combination of Script include & onChange() client script
In addition, should work well in native UI. For portal you can try making the 'Isolate script' to false once for a check.
g_form.getDisplayBox('field name').value;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2020 04:18 AM
Hi,
As
https://docs.servicenow.com/bundle/paris-application-development/page/script/ajax/topic/p_AJAX.html#p_AJAX
Hope it helps!
Regards,
Max.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2020 04:35 AM
Try below script.
OnChange() catalog client script on User variable
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('locationDetails');
ga.addParam('sysparm_name','getDetails');
ga.addParam('sysparm_req_for',newValue); //newValue will requester for
ga.getXML(callback);
function callback(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
var res = JSON.parse(answer);
g_form.setValue('u_location',res.loc); // enter correct variable name here
}
}
Create script include.
Name - locationDetails
client callable - true
var locationDetails= Class.create();
locationDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDetails :function(){
var res =
{
loc:''
}
var cat_user=this.getParameter('sysparm_req_for');
var gr=new GlideRecord('sys_user');
gr.addQuery('sys_id',cat_user);
gr.query();
if(gr.next())
{
res.loc = gr.getDisplayValue('location');
}
return JSON.stringify(res);
},
type: 'locationDetails'
});
Thanks,
Dhananjay.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2020 08:58 PM
Hi
Do we need follow up on this?
If this has resolved kindly mark this as correct and close the thread so others will refer same in future.
Thanks,
Dhananjay.