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

Hi Chuck,



Thanks. But i tried the same thing first and it is not working.


Workflow stuck there :


find_real_file.png



This is what I have given in the If Condition:


find_real_file.png



Please review & let me know.




Thanks & Regards,


Bhoomika


Red means there is an error somewhere in the script. Hover over the activity on the workflow and see what it says. My code was meant as a sample and may require updates. I don't know what your choice values are for used_for. It is more likely 'Production', but that does not dismiss the error. You need to find out what that is first. Check the workflow logs, check under System Logs> Logs> Error (and Warning.) See what turns up there. It could be a stupid mistake on my part.


No actually the problem is that used_for field is not available on cmdb_ci table. For example it is available in service_offering, business_service some tables like this.And the records of these tables are also available under cmdb_ci.


This is the main problem where i got stuck and not getting how to resolve exactly.



I will check the logs as well.



Regards,


Bhoomika


You could always check for the field before using it...



if (current.cmdb_ci) {


if (current.cmdb_ci.used_for) {


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


          return 'yes';


    }


}


}



return 'no';


Same error in the workflow.



Regards,


Bhoomika