Dot walking in gs.getUser()

laszlobolya
Kilo Expert

  Hello,

I need to get the information of the logged in user. I need to know his/her department and the country's ISO value.

var deptID = gs.getUser().getRecord().getDisplayValue('department'); // works. gives me back the user's department name

  var conVal = gs.getUser().getRecord().getDisplayValue('u_country'); // works. gives me back the user's country name

  var ISOVal = gs.getUser().getRecord().getDisplayValue('u_country.iso3166_3'.); // NOPE, addinfomessage returns empty

iso3166_3 is a field on Country table, label is ISO Long. How do I get access to it for the logged in user?

Many thanks!

1 ACCEPTED SOLUTION

thameem1
Kilo Expert

Hi,


As far as I am aware you cannot dot walk inside a reference field. From your code it looks u_country is reference field and to get u_country.iso3166_3 which is inside the reference field it is not possible by dot walking(as dot will get you access to only the object present in that reference). Instead you can use



var gr = GlideRecord(ref_table for u_country);


gr.addQuery(sys_id,gs.getUser().getRecord().getDisplayValue('u_country'));


gr.query();


if (gr.next()){


var ISOVal = gr.iso3166_3;


}



Thanks


Thameem


View solution in original post

3 REPLIES 3

thameem1
Kilo Expert

Hi,


As far as I am aware you cannot dot walk inside a reference field. From your code it looks u_country is reference field and to get u_country.iso3166_3 which is inside the reference field it is not possible by dot walking(as dot will get you access to only the object present in that reference). Instead you can use



var gr = GlideRecord(ref_table for u_country);


gr.addQuery(sys_id,gs.getUser().getRecord().getDisplayValue('u_country'));


gr.query();


if (gr.next()){


var ISOVal = gr.iso3166_3;


}



Thanks


Thameem


Hello Thameem, many thanks!



With a small modification it works:



var gr = GlideRecord('core_country');


gr.addQuery('name',gs.getUser().getRecord().getDisplayValue('u_country'));


gr.query();


if (gr.next()){


var ISOVal = gr.iso3166_3;


// gs.addInfoMessage(ISOVal);


  return ISOVal;


}



I can use this script in script include and set a filter with the script include name. Again, many thanks!


You are Welcome!


Please mark correct if it solved your requirement



Thanks


Thameem



Link for help to mark correct


How To Mark Answers Correct From Community Inbox