- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2020 02:52 PM
Whats the proper way to query a glide record so you can populate a reference field when creating an incident with an inbound email action? The code blow is one of my attempts to do so. loc is a string containing a valid location, and its done that way because I'm pulling the string out of emails body. I've tried using 'get' and have made numerous small changes, but when an incident is created any reference fields I try to populate remain empty. So my main question is, whats the correct way to query GlideRecord with a string in order to get a sys_id which is necessary for defining reference fields? Thanks for any advice!
var glide = new GlideRecord('sys_user');
glide.addQuery('location', loc);
glide.query();
if(glide.next()){
current.location = glide.sys_id;
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2020 02:58 PM
Location records are stored in the "cmn_location" table. Replace your script with the below script that I've shared.
var glide = new GlideRecord('cmn_location');
glide.addQuery('name', loc);
glide.query();
if(glide.next()){
current.location = glide.sys_id;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2020 02:58 PM
Location records are stored in the "cmn_location" table. Replace your script with the below script that I've shared.
var glide = new GlideRecord('cmn_location');
glide.addQuery('name', loc);
glide.query();
if(glide.next()){
current.location = glide.sys_id;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2020 03:13 PM
Closer I think, but still no dice. The field is empty. Should 'name' be something else? Not sure if any of these images will help, sorry for the clutter. Thanks tho, wicked fast response.
Edit: I realized your solution did work, but not in the area I expected. The location column when viewing incidents is populated now, but oddly enough when I click the incident to go in for more details, the location will be empty in there. Any thoughts on this?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2020 03:40 PM
Hi Wwinter,
Could you please replace line current.location = glide.sys_id; with current.location = glide.getValue("sys_id");
- Pradeep Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2020 03:59 PM
Its still just populating the table like mentioned above, although I'm fairly happy about that. I think that the tables location data and the location field when you click the incident pull from different locations. Thanks for helping me get this far!
Edit: As it turns out, the location field being displayed internally was Contact.Location, which is fine for some things, but wasn't what we were changing. I added in just plain 'location', and its working like a charm.