The CreatorCon Call for Content is officially open! Get started here.

Is it possible to get data of reference fields without using Script include?

Raj_Esh
Kilo Sage
Kilo Sage

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

 

 

--Raj
1 ACCEPTED SOLUTION

Raj_Esh
Kilo Sage
Kilo Sage

Thank you @Paul Morris and @sudeepptr 

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);

--Raj

View solution in original post

7 REPLIES 7

The SN Nerd
Giga Sage
Giga Sage

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

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

--Raj

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

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

--Raj