- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 01:20 PM
I have a sys_id value of a table and I want to find out the table associated with that sys_id. Is there any way i can find out the table or record name using the sys_id?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 01:48 PM
Hi Sandeep,
Sample script here. Please adjust it as per your need.
var gr = new GlideRecord('sys_db_object');
gr.addQuery('sys_id','YOURSYSID HERE');
gr.query();
while(gr.next())
{
gs.addInfoMessage(gr.name); //This will give you table name
}
Business Rules - ServiceNow Wiki
Business Rules Best Practices - ServiceNow Wiki
You can fire it from Background script for testing purpose. More info here.
Background Scripts — ServiceNow Elite
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2017 07:23 AM
Hi All,
I have tried using the script mentioned above but I did not get the table name after running it in background script:
Here is my script:
var gr = new GlideRecord('sys_db_object');
gr.addQuery('sys_id','b5173b1d0f10860047e27d4ce1050eed');
gr.query();
while(gr.next())
{
gs.print(gr.name);
}
I just replaced addInfoMessage with print.
Any suggestions would be helpful thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2017 07:49 AM
Hello harsha
Please change gs.print to gs.info
Updated Script:
var gr = new GlideRecord('sys_db_object');
gr.addQuery('sys_id','b5173b1d0f10860047e27d4ce1050eed');
gr.query();
while(gr.next())
{
gs.info(gr.name);
}
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2023 10:31 AM
Hi harshayer,
It seems there was a lot of confusion regarding your question. I've run into a similar issue where I'm looking for the table that contains a certain sys_id, for a host of reasons. The reply from Pradeep contains a simple query that rolls through the sys_db_object table which contains a list of all the tables, regardless of scope. The part he missed is to add a 2nd nested sub query that will roll through each table, one at a time, and look for your specified sys_id, returning the table name if/when it's found. As noted by another reply, that can be very time and resource intensive so you might consider creating a Fix Script with this script to run in the background and simply update/add a row to a table if/when a table name is found. Hope this helps!