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

This is what i am getting:


find_real_file.png


And this in logs:


find_real_file.png


This is I am getting in Error Logs



Thanks & Regards,


Bhoomika


You commented out the critical parts the template gives you. The entire script should include:



answer = ifScript();



function ifScript() {


  if (current.cmdb_ci) {


      if (current.cmdb_ci.used_for) {


        if (current.cmdb_ci.used_for == 'production') {


            return 'yes';


        }


    }


}



return 'no';


}


BALAJI40
Mega Sage

Hi Bhoomika,



  workflow will run on sc_req_item table, if you write like that means it will not work out.


You need to glide record on that chenge request table, then you can verify that condition.


mansoor3
Tera Contributor

Hi Bhoomika,



If you want to get current table name current.cmdb_ci.getTableName().


For Reference field table name, example field name is configuration item current.cmdb_ci.sys_class_name.



Code: gs.addInfoMessage(current.cmdb_ci.sys_class_name);



Output:


answer.png



- Mansoor


PS - Please mark Helpful, Like, or Correct Answer if applicable.