Getting a record by sys_id using .get

brozi
ServiceNow Employee
ServiceNow Employee

I was looking for an easy way to get to a record using the sys_id. In the past i would use the following and query the record

var util = new GlideRecord('u_send_web_service');
util.addQuery('sys_id', "d8881aff4a36232d012101e1684bff0a");
util.query();
while (util.next()) {

There is an easier way or using less scripting to get that record. You can use .get to get the record. Example below.

var util = new GlideRecord('u_send_web_service');
util.get("d8881aff4a36232d012101e1684bff0a");

John R. thanks for the help!!

2 REPLIES 2

john_roberts
Mega Guru

You can also specify a field. The get method only returns the first record so you should always make sure the query is unique to a single record.

var inc = new GlideRecord('incident');
inc.get('number','INC12345');


Not applicable

Also not that the get() function actually returns a boolean to indicate if a record was found or not.
Example:

var gr = new GlideRecord('incident');
var foundit = gr.get()
gs.print('found it = ' + foundit)

var foundit = gr.get()
gs.print('found it = ' + foundit)