Catalog Client Script Dot Walk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2021 05:21 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2021 05:32 AM
Hello,
Make use of getReference() for the callback
var location = g_form.getReference(‘var_loc’, showRegion);
function showRegion(location) {
alert(location.u_region);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2021 05:45 AM
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
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2021 05:56 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2021 06:11 AM
What is the field type of u_region on the cmn_location table?