- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on ‎01-26-2021 08:58 AM
//Find table based on sys_id.This script should be run as admin user in global scope. Script gives output as table name and sysId
Link to video:https://youtu.be/_DT34P734NA
github link : https://github.com/anilvaranasi/ServiceNow
//Developed by Srinivas Anil Kumar Varanasi
//This script should be run as admin user in global scope
//Script gives output as table name and sysId
//Find table based on sys_id.
runQueryonTables();
function runQueryonTables() {
var sLog = '';
var outputJson = {};
var tableList = [];
var outputList = [];
var sysId = '2f738cab0f3600105bc5e7b1d4767e3b'; // sys_id to be updated based on requirement
var grTable = new GlideRecord('sys_db_object');
grTable.query();
while (grTable.next()) {
tableList.push(grTable.name + '');
}
for (var m = 0; m < tableList.length; m++) {
outputJson = runQuery(tableList[m], sysId);
outputList.push(outputJson);
}
for (var k = 0; k < outputList.length; k++) {
if(outputList[k].output.length >0) {
sLog += outputList[k].tableName + "=" + outputList[k].output + "\n";
}
}
gs.print("Tables matching sys_id =" + sLog);
}
function runQuery(tableName, sysId) {
var output = '';
var outputJson = {};
try {
var grQuery = new GlideRecord(tableName);
grQuery.query('sys_id', sysId);
grQuery.query();
if (grQuery.next()) {
output = grQuery.sys_id + '';
}
} catch (err) {
output = 'no access to table ' + err;
}
outputJson = {
"tableName": tableName,
"output": output
};
return (outputJson);
}
- 3,075 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I wanted to thank you for providing this script. I have a custom UI page that was prepared by a contractor who didn't leave complete documentation. I was able to use this and locate the table / record where the sysID was located in only a matter of minutes as the script ran. It worked perfectly. Many thanks for your contribution to the community.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks @Jeffrey Jackson appreciate you taking time and leaving this note, means a lot 🙂
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Srinivas,
Your script greatly helped as well. I had to find a record of a Sys ID and wondering how to get it an efficient way. Your script worked like a magic. Thank you!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks @Suresh K1