- 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-17-2016 06:43 AM
I would love to see the solution if it is working. Please share.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2016 06:47 AM
Hi Chuck and Pradeep,
I think i created a confusion. The req is very simple, i just need to get the table name based on the sys_id.
so the script provided by pradeep worked which is very simple. We are querying the sys_db_object which stores all the tables and adding the sys_id to that query. Now in the loop we are printing the table name.
var gr = new GlideRecord('sys_db_object');
gr.addQuery('sys_id','sys_id_of the table');
gr.query();
while(gr.next())
{
gs.addInfoMessage(gr.name);
}
Thanks,
Sandeep

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2016 06:49 AM
Got you
Would you mind marking answer and close the loop if your query is resolved now.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2016 06:49 AM
Thank you for clarifying Sandeep. I thought you were after the record ID of the specific record, not the record ID of the table.
I'm glad you got it figured out.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2016 12:44 AM
This does work, but it's not the preferred way to do this. Instead of using
gr.addQuery('sys_id','YOURSYSID HERE');
you should just do
gr.get('YOURSYSID HERE');