How to find the table name using Sys_id of a form value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 03:51 AM
Hi All,
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 05:59 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 06:14 AM
Yes exactly the same.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 06:19 AM
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';
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 06:21 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 06:26 AM
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?