How to dot walk from user table to core country table

Souvick A
Tera Contributor

Hello All

I have a requirement as below:

Navigate from user table to core country table for a field value.

sys_user > cmn_location > core_country.

The user table contains a OOB field 'Location'  from there I will direct to a customized field 'Country' on cmn_location table and then I need to fetch the data on ISO Short field value on core_country table.

Note: Al these are reference fields. 

I want guidance on formulating this in a script include to compare the value of ISO Short field with incoming data.

Regards

Souvick

5 REPLIES 5

Sourabh26
Giga Guru

Hi,

Use below code

location.country_field.getDisplayValue();//to get the value of the field

or

location.country_field.getValue();//to get the sys_id of the field

 

Mark this as Helpful/Correct, if Applicable.

 

Regards,

Sourabh

Shruti
Mega Sage
Mega Sage
 
Hi,
 
Use location.u_user_country.iso3166_2;  //Replace 'u_user_country' field with the custom Country field name on Location table 
 
Try below code in background script
 
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('name=System Administrator'); //Make sure location and country field is not empty for the user
gr.query();

if(gr.next()){

gs.info(gr.location.u_user_country.iso3166_2); //Replace 'u_user_country' field with the custom Country field name on Location table 

}

In order to have dynamic user in gr.addEncodedQuery , what will be the code in script include. In background script , I can see value for sys id, but what will be in script include?

Hi,

 

What is the condition on which this functionality will run? 

Ex. On creation of new user in sys_user table.

In that case you need to write the BR on user table and call the script include.

 

Let me know the details to provide you the script.

 

Regards,

Sourabh