- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2015 09:38 PM
Is there a way to identify the record in an instance just based on the sys_id, without knowing the table name?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-29-2015 09:21 AM
I just wrote and tested the following scheduled job which will look for a table that has a record with a particular sys_id. I exclude some tables from the search.
do_find_sys_id('e836b3e5b0be02008cbdd6bd573aaccf');
function do_find_sys_id(sys_id) {
var job_name = 'Find sys_id';
gs.log('========== Begin ' + job_name + ' for ' + sys_id + ' ==========');
var table_name = [];
var table = new GlideRecord('sys_db_object');
table.orderBy('name');
table.query();
while (table.next()) {
if ((table.name.toString() != '') &&
(table.name.toString().substring(0,2) != 'ts') &&
(table.name.toString().substring(0,2) != 'v_') &&
(table.name.toString().substring(0,3) != 'dis') &&
(table.name.toString().substring(0,3) != 'dsc') &&
(table.name.toString().substring(0,3) != 'ecc') &&
(table.name.toString().substring(0,3) != 'ha_') &&
(table.name.toString().substring(0,3) != 'wf_') &&
(table.name.toString().substring(0,3) != 'win') &&
(table.name.toString().substring(0,4) != 'sysx')) {
//gs.log('Processing table ' + table.name + ' (' + table.name.toString().substring(0,3) + ').');
var object = new GlideRecord(table.name);
if (object.get(sys_id)) {
table_name.push(table.name.toString());
}
}
}
if (table_name) {
gs.log('Found ' + sys_id + ' in ' + table_name.join(', ') + '. Use nav_to.do?uri=' + table_name[0] + '.do?sys_id=' + sys_id);
}
else {
gs.log('Did not find sys_id ' + sys_id + '.');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2022 06:30 AM
From time to time the solution needs a face-lift.
New tables appear in the platform and additional exceptions should be added.
The DevTools app contains powerful tools and a code library for ServiceNow developers.
One of them is the GetTableFromSysId() function. Check it out here:
It excludes a number of tables from the search and searches a number of tables first, where I believe the likelihood of a match is higher - which makes it faster in many cases than the earlier proposed solutions.