- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2022 05:18 AM
Hi
I have a value like which is the name of the location which i need to set in the refernence field which is location.
Can i do like below?
gr.u_location = "India"; // u_location is a reference field
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2022 05:30 AM
Hi Shaik Irfan,
What you need to do is something like this:
var locations = new GliedRecord("cmn_location");
locations.get("name",<variable or literal with the name>);
gr.setValue("u_location", locations.sys_id);
Hope that helps.
:{)
Helpful and Correct tags are appreciated and help others to find information faster
:{)
Helpful and Correct tags are appreciated and help others to find information faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2022 05:30 AM
Hi Shaik Irfan,
What you need to do is something like this:
var locations = new GliedRecord("cmn_location");
locations.get("name",<variable or literal with the name>);
gr.setValue("u_location", locations.sys_id);
Hope that helps.
:{)
Helpful and Correct tags are appreciated and help others to find information faster
:{)
Helpful and Correct tags are appreciated and help others to find information faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2022 05:31 AM
Hi,
If location is reference field you should set sys_id as the value. ie., you should set 'india' sys_id to the gr.u_location field.
You are not aware of sys_id of india then you should glide the value from required table.
I'm not sure which table it holds the value.
Regards,
Suresh.
Suresh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2022 05:32 AM
function ID(val){
var s= new GlideRecord('cmn_location');
s.addQuery('name',val);
s.query();
if(s.next())
{
return s.sys_id;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2022 05:35 AM
Hi,
if you are sure the location name is exact then you can use setDisplayValue to set the display value
gr.setDisplayValue('u_location', 'India');
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader