- 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
‎06-16-2016 01:28 PM
Hi Sandeep,
Not that I can find. You would have to write a script to go through each table in the dictionary and see if your sys_id matches any records in each table. With approximately 2000 tables, this is less than optimal.

- 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
‎06-16-2016 01:52 PM
Hi Pradeep,
Two issues I have with that script. First, it's missing a gr.query(), second, it didn't work. You are querying a specific table for a specific record. I threw a sys_id from sysevent_email_action and it didn't retrieve the name of the table from sys_db_object. Sorry.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 01:56 PM
Thanks Chuck. I made edit and updated the script. The script didn't got copied properly
So now I think the question is can I pass the sys_id of the table and retrieve the name..Yes it should work if you pass the sys_id of the record.
Correct me if I am wrong or missing something.