Search sys_id in entire Servicenow instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2017 08:15 AM
Hi,
I have a doubt regarding searching records in Servicenow. Given the sys_id and the table, there is a possibility to get the corresponding record. My doubt is given only the sys_id, is it possible to get a record corresponding to the sys_id?
I'm asking this because I read that the sys_id is unique across an instance. So given a sys_id, there must be only one corresponding record in an entire instance.
I'd like to know the possibility using code (Glide API), and searching in UI.
Please assist.
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2019 06:42 AM
This statement is incorrect that given a sys_id, there must be only one corresponding record in an entire instance. The same sys_id can exist for 2 or more records, but those records would not belong to the same table. In one table, every record will have a unique sys_id, not necessarily in 1 instance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2019 04:11 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2019 04:39 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2020 10:49 PM
Hi in the background script use below code (**do not run in production instance**)and do some appropriate modifications as per your requirement
var grIncident = new GlideRecord('incident');
var returnValue = grIncident.get('27cf23772fc64c108b3157ab2799b6fb');
gs.info(returnValue); // logs true or false
gs.info(grIncident.number);
Mark correct and helpful if you able resolve issue
Thanks
Rajender
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2020 12:52 AM
Use the below code to search for sys id
var GlobalSearch = Class.create();
GlobalSearch.prototype = Object.extendsObject(AbstractAjaxProcessor, {
bySysId: function(sys_id){
var response = [];
response[0] = false;
var tables = new GlideRecord('sys_db_object');
tables.addNullQuery('super_class');
// This table doesn't admit aggregated queries
tables.addQuery('name','!=','sn_m2m_note_template_for_table');
// These tables don't have sys_ids
tables.addQuery('name','!=','pa_scores_l1');
tables.addQuery('name','!=','pa_scores_l2');
tables.addQuery('name','!=','sys_rollback_incremental');
tables.addQuery('name','!=','sys_rollback_sequence');
tables.addQuery('name','!=','pa_migration_ignored_scores');
tables.addQuery('name','!=','pa_favorites');
tables.orderBy('name');
tables.query();
var avoidTables = /^(ts_|v_|sn_hr_)/;
while(tables.next()){
var table = tables.getValue('name');
try{
if(!table.match(avoidTables)){
var agg = new GlideAggregate(table);
agg.addAggregate('COUNT');
agg.addQuery('sys_id',sys_id);
agg.query();
if(agg.next())
if(agg.getAggregate('COUNT') > 0){
response[0] = true;
response[1] = tables.getValue('name');
return response;
}
}
}catch(e){
// Some tables might cause exceptions we don't need to hear about
}
}
return response;
},
type: 'GlobalSearch'
});
