Whats the correct way to query a string with GlideRecord?

wwinter
Kilo Contributor

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;
	}

find_real_file.png

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

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;
	}

View solution in original post

5 REPLIES 5

You are very welcome @wwinter. If you can reproduce this on your Personal developer instance, I can investigate this issue. 

- Pradeep Sharma