Search for a specific sys_id
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-22-2015 06:49 PM
Search for a sys_id in your entire serviceNow instance.
Some time your scripts/logs may spit out a sys_id that you cant identify without spending some time to manually search for it.
This script will automatically search for the sys_id and return more data to identify the record.
The time taken for this will vary depending on the size of the instance. Off my dev instance, it took about 2 mins.
Works by searching all the tables via the "sys_db_object", then applying that table name to another query, which then searches for a second time.
The results are spit out in script logs
Recommended for a developer who knows what they are doing, but is currently safe as is. **use/modify at your own risk**
Code to delete the found record is commented out at the top. Untested and possibly dangerous.
Install by creating a fix script and change the 'searchSys_id' variable at the top of the script. Then run.
You need appropriate roles to run the fix script. - admin.
Please post any enhancement you may make.
FIX SCRIPT:
Script
//Delete multiple records according to the current "where" clause. Does not delete attachments.
//y.deleteMultiple()
//boolean y.deleteRecord()
var searchSys_id = "e6303e0b4fb34200501030318110c7b7";
var x = new GlideRecord('sys_db_object'); //sys_db_object
- x.addActiveQuery();
- x.query();
//gs.log(x.getRowCount());
while(x.next())
{
//gs.log(x.name);
if(x.sys_id == searchSys_id ) // Checks tables own sysID
gs.log(" ID: " + x.sys_id + "Table Name: " + x.name + " Class: " + x.sys_class_name);
try
{
var y = new GlideRecord(x.name);
y.addQuery('sys_id',searchSys_id);
y.addActiveQuery();
y.query();
while(y.next())
{
if(y.sys_id == searchSys_id ) // NEED this double check or else log will spit out alot lot of rubbish
{
gs.log(" ID: " + y.sys_id + " Table Name: " + x.name + " Name: " + y.name + " Class: " + y.sys_class_name);
gs.log(y.getRowCount());
}
}
}
catch(e)
{
gs.log("ID ERROR: " + e);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2017 03:46 PM
var SYSIDSearch = "774190f01f1310005a3637b8ec8b70ef";
var complete = false;
var gr = new GlideRecord('sys_db_object');
if (gr.get(SYSIDSearch)) {
gs.log(gr.name, 'SYSIDSearch');
complete = true;
}
else {
gr = new GlideRecord('sys_db_object');
gr.addActiveQuery();
gr.query();
}
while(gr.next() && !complete) {
try {
var grB = new GlideRecord(gr.name);
if (grB.get(SYSIDSearch)) {
gs.log(gr.name, 'SYSIDSearch');
complete = true;
}
}
catch(e) {
//who cares
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2017 04:39 PM
Here's the script I use when searching for a sys_id - Useful Background Script - Find a record by its sys_id
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2017 05:05 PM
And another for when I need to find records created/updated within a certain time window - Useful Background Script - Find records created/updated within a time window
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-18-2018 09:50 PM
Another enhanced searching tool
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2022 06:43 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 many other proposed solutions.
