
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 04:05 PM
Hello Guys,
I am trying to understand the process to get the data of reference fields.
Example:
A REQ000111 has Opened_by reference filed and is referred to User table. And on the user table, another reference field is called Location.
The Location has different variables. Example City, Country, etc.
How can we get the value of City or State without using Script Include?
Help on this is much appreciated.
Thanks,
Raj
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2022 03:36 AM
Thank you
Looks like have to use script include, without which the values are not retrieved.
Code for reference:
Script Include:
getlocation: function() {
var sys = this.getParameter('location_id');
var cm_loc = new GlideRecord('cmn_location');
if (cm_loc.get(sys)) {
gs.log('location ' + cm_loc.country);
answer = cm_loc.country;
gs.log('answer' + answer);
}
return answer;
},
Client Script:
var l = g_form.getReference('opened_by');
var ll = l.location;
ga.addParam("sysparm_name", "getlocation");
ga.addParam("location_id", ll);
ga.getXMLWait();
// alert(ga.getAnswer());
var loc = ga.getAnswer();
alert(loc);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 04:08 PM
You can add those fields through dot walking if you configure the form via 'Form Layout' instead of 'Form Desinger'.
You can also pull that data to the scratchpad on display business rules which can be used in client scripts.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 04:11 PM
Hey Paul,
Thank you for your quick response.
I have custom UI and I am trying to get those details.
Wondering if I can get those details only with the client script.
I tried below code but was able to get one level and that's only the sys_id 😞
var l = g_form.getReference('opened_by');
var ll = l.location;
Thanks,
Raj

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 04:18 PM
If this is a UI page or UI Macro you could declare a jelly variable to get this data.
Can you elaborate more on what you mean by "I have custom UI" ?
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 04:23 PM
I have a custom UI page on REQ form, on which I am trying to display the reference values(country, street, etc).
Can you please share a sample jelly code to get such details?
Thanks,
Raj