Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Catalog Client Script Dot Walk

ceraulo
Mega Guru

Hello!

I have a catalog client script shown below. It aims to get the region of the location variable from the cmn_location table.
My script returns undefined when I used getDisplayValue. If I remove getDisplayValue, it returns the sys_id.

function onLoad() {

    var loc = g_form.getValue('var_loc');
	
    var gr = new GlideRecord('cmn_location');
    gr.addQuery('sys_id', var_loc);
    gr.query(myCallbackFunction);

    function myCallbackFunction(gr) {
        while (gr.next()) { 
			
			alert(gr.u_region.getDisplayValue());

        }
    }

}

Please help!

Thank you.

12 REPLIES 12

ajayr
Giga Expert

Hello,

 

Make use of getReference() for the callback

 

var location = g_form.getReference(‘var_loc’, showRegion);

function showRegion(location) {
alert(location.u_region);
}

Brad Bowman
Kilo Patron
Kilo Patron

GlideRecord in client scripts is not recommended/supported/best practice.  Replace this with a getReference including a callback, or a GlideAjax calling a script include.  Your custom field u_region must be a reference to another table since you're getting sys_id, so on the getReference dot-walk it to the field that contains the display value / name string.  Here's an example

var location = g_form.getReference(‘var_loc’, showRegion);

function showRegion(location) {
  alert(location.u_region.name); //replace 'name' with the display field name
}

Hi Brad. u_region is taken from the same table, cmn_location. 
I think location.u_region is the right one but not returning the value I'm expecting.

What is the field type of u_region on the cmn_location table?