Getting a record by sys_id using .get
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2008 09:42 AM
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!!
- 43,761 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2008 09:48 AM
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');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2008 11:06 AM
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)