The CreatorCon Call for Content is officially open! Get started here.

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

The code should be



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


  var tableName = current.cmdb_ci.sys_class_name;


  gs.addInfoMessage(tableName);


})(current, previous);



You had current.cmdb.sys_class_name, not current.cmdb_ci.sys_class_name.



The other interesting part is that the line of code should only run once, yet you have multiple messages being displayed. That suggests the BR is being triggered multiple times which can be very inefficient. I recommend turning on Business Rule debugging to see when and why that business rule is being triggered.



See section 3.1.2 here


Debugging Tools Best Practices - ServiceNow Wiki


Hi Chuck,



This is working now but yes it is giving multiple lines


find_real_file.png


Thanks & Regards,


Bhoomika


gs.addInfoMessage(current.cmdb_ci.getTableName())


Just Use this line.


Both sys_class_name and getTableName() are to get the table.


Inactive_Us1474
Giga Guru

Reason its not working because both the sys_id's are different, you are using a particular record of cmdb_ci   sys_id and comparing it with the table name cmdb_ci sys_id.



Thanks


Akhil


BALAJI40
Mega Sage

  var gr = new GlideRecord('sys_db_object');// store all table info


  gr.addQuery('sys_id',ci_sysid);// Here you are comparing table name sys id with table record sysid


Its not workout.


tell me your requirement more in detail.