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

Just so I understand... you're able to input ANY CI in the cmdb_ci field, but you are only getting approval on those that are used in production, and since the used_for field is not available on classes, we're getting an error, right?


Yes exactly the same.


Let's add some debug statements to ensure how far you are getting through the script. I just ran a simple test using my "if (current.cmdb_ci.used_for)" test and it worked without errors on a CI that does not have a used_for field.



gs.log('10: Started');


if (current.cmdb_ci) {


  gs.log('20: ci is good');


if (current.cmdb_ci.used_for) {


  gs.log('30: used_for defined and not null');


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


          gs.log('40: production CI');


          return 'yes';


    }


}


}


gs.log('50: No');


return 'no';




Yes user can give any CI as an input, then we have to check if the CI is used for production or not. And also the table to which that CI value belongs does it even have the used_for field, if yes then check whether it is used_for production or not.



If it is used for production then it should go for CAB approval else it should directly move to Schedule State.


The logic I have written does what you describe. See the latest script with the gs.log() statements to help track down where the red error is coming from.



Were you able to find any information in the Workflow logs regarding the error?