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.

dot walking returns undefined

Salzo
Giga Contributor

Hello,

 

I am trying to retrieve information from a reference field but am getting "undefined"

 

I have tried the below so far

	gs.info("!>>> country" + gr.cmn_location.u_countries.getValue('u_country'));
	gs.info("!>>> country" + gr.cmn_location.u_country_cd_iso2.getValue('u_country'));
	gs.info("!>>> country" + gr.Location.u_country_cd_iso2.Counry.toString);

 

The field in form manager looks like this

 

find_real_file.png

 

Other field on the GR return fine?

 

How do I retrieve information contained in reference fields?

 

 

8 REPLIES 8

Salzo
Giga Contributor

Hi,

 

the getValue part isnt the problem I replaced it with getDisplayValue and it still wont work..

 

here is what I am trying to do

 

//get user object
var userObj = new GlideRecord('sys_user');
userObj.get('6440d3a85dbe20004abfd62e32a38932');


//get user country
var userCountry = userObj.cmn_location.u_countries.getDisplayValue('u_country'));

 

//when I gs.info userCountry its empty?

 

 

//look for custom table tasks for users country

var gr = new GlideRecord('cases');
gr.addQuery('u_country',userCountry );
gr.query();

while(gr.next()){
//do stuff

}

USe below sample code

 

var userObj = new GlideRecord("sys_user");
userObj.get('62826bf03710200044e0bfc8bcbe5df1');
userObj.query();
gs.print(userObj.location.country);

why are you quering again do you need that statement.

 

var userObj = new GlideRecord("sys_user");
userObj.get('62826bf03710200044e0bfc8bcbe5df1');
userObj.query(); // I feel this is not needed
gs.print(userObj.location.country);

Abhinay Erra
Giga Sage

Here you go

 

//get user object
var userObj = new GlideRecord('sys_user');
userObj.get('6440d3a85dbe20004abfd62e32a38932');

//get user country
var userCountry = userObj.location.u_countries.getValue('u_country');

 //when I gs.info userCountry its empty?

 //look for custom table tasks for users country

if(userCountry){

var gr = new GlideRecord('cases');
gr.addQuery('u_country',userCountry );
gr.query();

while(gr.next()){
//do stuff

}

}