How to find a Table Name using sys_id?

harshayer
Tera Contributor

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?

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

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  


View solution in original post

17 REPLIES 17

I would love to see the solution if it is working. Please share.


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


Got you


Would you mind marking answer and close the loop if your query is resolved now.


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.


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');