Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to find the table name using Sys_id of a form value

bhoomikabisht
Kilo Expert

Hi All,

ctomasi

I want the table name of the record based on sys_id  

i have tried below code in query business rule before , its not working

(function executeRule(current, previous /*null when async*/) {

  // Add your code here

  var ci_sysid = current.cmdb_ci.sys_id;

  var gr = new GlideRecord('sys_db_object');

  gr.addQuery('sys_id',ci_sysid);

  gr.query();

  while(gr.next())

  {

  gs.addInfoMessage(gr.name);

  }

})(current, previous);

please help

Thanks

Bhoomika

28 REPLIES 28

Geoffrey2
ServiceNow Employee
ServiceNow Employee

If it's just CI's then you can use current.cmdb_ci.sys_class_name to get the table name.


Hi Geoffrey,


I tried the code you mentioned above as :


(function executeRule(current, previous /*null when async*/) {


    var tableName = current.cmdb_ci.sys_class_name;


  gs.addInfoMessage(tableName);


})(current, previous);



And I got this :


find_real_file.png



It's not working



Please review & let me know.



Thanks & Regards,


Bhoomika


Chuck Tomasi
Tera Patron

If you have a reference to the sys_id, then you should also have a table name with



var tableName = current.cmdb.sys_class_name;



No need to query every table on the system to find out.


Hi Chuck,



I modified the code as per your suggestion :



(function executeRule(current, previous /*null when async*/) {


  var tableName = current.cmdb.sys_class_name;


  gs.addInfoMessage(tableName);


})(current, previous);



And below is the result:


find_real_file.png


I am not able to get the table name



Please review and let me know.



Thanks & Regards,


Bhoomika