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

Community Alums
Not applicable
If you want to access that directly in the business rule you can just dot walk that. https://docs.servicenow.com/bundle/rome-platform-user-interface/page/use/navigation/reference/dot-walking-examples.html

Hi Sudeep,

 

Thank you, but I am looking more on the jelly or the client scripts to get the values.

 

Thanks,

Raj

--Raj

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