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

Aman Gurram
Giga Expert

Hi Salzo,

 

getValue and SetValue dont work with Dot Walking 

In your code to the values, dot walk further 

 

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

Abhinay Erra
Giga Sage

getValue() method should work. But I see you are using cmn_location as the field name which is a table name instead. Can you post the entire code and let me know what you are trying to achieve.

Dubz
Mega Sage

You can use getValue but if you've dot-walked a bit you need to just put it on the end as below: (also note toString() is a method and so needs the brackets)

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

Aman Gurram
Giga Expert

Please take a look at this post to see why using a getValue wont work. 

https://community.servicenow.com/community?id=community_question&sys_id=e34bc321db9cdbc01dcaf3231f96...

You can either do something like 

gs.info("!>>> country" + gr.cmn_location.u_countries..getRefRecord().getValue('u_country'));

Or 

gs.info("!>>> country" + gr.cmn_location.u_countries.u_country.getDisplayValue());