Convert reference field LOCATION to display name instead of Sys ID

IB98
Giga Sage

HI All, 

(Catalog Item) I am trying to get the variable 'location' to auto populate with the requester information. Initially, the location populates with the signed in requester because I have a default javascript in place that does that. If I change the user, the OnChange script is supposed to set the value for that user, instead it displays the sys id. I did check the display on the location table and it's set to true on name. I am out of ideas. Please help!

I will include the variable default code and the Catalog client script. Also, the location variable is set to a single line text variable.

*I have tried both options that are commented out. The above script works for phone and email variables. 

 find_real_file.png

*Location (Single line text variable) to populate 'Requester' (variable set variable) Location  

find_real_file.png

Thanks, 

1 ACCEPTED SOLUTION

IB98
Giga Sage

Thank you all for your help! I used this code and it helped.

Script Include 

var getLocation = Class.create(); 

getLocation.prototype = Object.extendsObject(AbstractAjaxProcessor, { 

    get_location: function() { 

        var gr = new GlideRecord('sys_user'); 

        gr.addQuery('sys_id', this.getParameter('sysparm_userID')); 

        gr.query(); 

        if (gr.next()) { 

            return gr.location.getDisplayValue(); 

        } 

    }, 

    type: 'getLocation' 

}); 

OnChange Catalog Client script 

function onChange(control, oldValue, newValue, isLoading) { 

if (isLoading || newValue === '') { 

return; 

} 

  

    var ga = new GlideAjax('getLocation'); 

    ga.addParam('sysparm_name', 'get_location'); 

    ga.addParam('sysparm_userID', g_form.getValue('requester')); //the variable name from the variable set

    ga.getXMLAnswer(function(answer){ 

       //if(answer != ''){ 

       g_form.setValue('location', answer); 

       //} 

    }); 

} 

View solution in original post

7 REPLIES 7

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

This dot walk feature on will not work on the getReference function. you will have yo use GlideAjax  and then return the fields needed from server side

-Anurag

-Anurag

naman1
Tera Contributor

Please try to use GlideAjax Call in order to get the display value of location field. You can return multiple values from Script Include using JSON object. Please try the below code in Script Include.

 

getUserData: function() {

var gruser = new GlideRecord('sys_user');
var user = this.getParameter('sysparm_user');

if (gruser.get(user)) {

var json = new global.JSON();
var results = {};


results.first_name = gruser.getValue('email');
results.last_name = gruser.getValue('phone');
results.location= gruser.getDisplayValue('location');

return json.encode(results);

}
},

IB98
Giga Sage

Thank you all for your help! I used this code and it helped.

Script Include 

var getLocation = Class.create(); 

getLocation.prototype = Object.extendsObject(AbstractAjaxProcessor, { 

    get_location: function() { 

        var gr = new GlideRecord('sys_user'); 

        gr.addQuery('sys_id', this.getParameter('sysparm_userID')); 

        gr.query(); 

        if (gr.next()) { 

            return gr.location.getDisplayValue(); 

        } 

    }, 

    type: 'getLocation' 

}); 

OnChange Catalog Client script 

function onChange(control, oldValue, newValue, isLoading) { 

if (isLoading || newValue === '') { 

return; 

} 

  

    var ga = new GlideAjax('getLocation'); 

    ga.addParam('sysparm_name', 'get_location'); 

    ga.addParam('sysparm_userID', g_form.getValue('requester')); //the variable name from the variable set

    ga.getXMLAnswer(function(answer){ 

       //if(answer != ''){ 

       g_form.setValue('location', answer); 

       //} 

    }); 

}