Fill Request country field based on user country code

kuba4
Kilo Expert

Hi There,

This is what I need to do: I have a field "Requester country" which I need to fill when Request is created, based on country of Requester.

Requester has an attribute of country, but it is in long ISO code (3 letters) instead of country name. I have country names mapped to ISO codes in "Country" table and "Requester country" is a reference field to that table. How to make that instead of ISO code from user record, field will be updated with full country name? 

Current code used to fill Request fields (based on call) is something like this:

 

var grRequest = new GlideRecord ("sc_request");
grRequest.initialize();
// copy fields from call to req
grRequest.requested_for = current.opened_by;
grRequest.opened_by = current.opened_by;
grRequest.u_region_high_level = current.u_call_region_high_level;
grRequest.u_requester_email = current.u_call_requester_email;
grRequest.u_requester_name = current.u_call_requester_name;

(...)

//I was trying to use line below but I know it can't work since it is updating ISO code and not full name.

grRequest.u_requester_country = current.u_call_requester_name.country;

(...)

 

Could you please help me with that?

 

Regards,
Kuba

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Is this field a reference type "u_call_requester_name"?

to which table it refers?

you will have to do something like this

var rec = new GlideRecord('country'); // give proper country table name here

rec.addQuery('iso_field', current.u_call_requester_name.country); // give valid iso field here

rec.query();

if(rec.next()){

grRequest.u_requester_country = rec.sys_id;

}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@kuba 

Hope you are doing good.

Let me know if that answered your question.

If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader