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 04:21 AM
Hope this will help you -
var ci_sysid = "XXXXXXXXXXXXXXXXXXXXXX"; // sysid you have
var t_gr = new GlideRecord('sys_db_object');
t_gr.addQuery('sys_id',ci_sysid);
t_gr.query();
if(t_gr.next()){
gs.addInfoMessage("table name:"+t_gr.name);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 05:00 AM
Please hit Helpful/Like/Correct answer if your issue is resolved.
Thanks,
Pratyush
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 05:01 AM
Can you expand a bit on what you are attempting to do? It is unlikely that a before business rule is the best course of action.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 05:14 AM
Hi Martin,
Actually I to find out whether the Configuration Item on Change Form is used for Production or not. So currently I am checking using Business Rule to check the code I am writing but I will apply the same in Workflow. The exact requirement is as: When is change form user gives a value for Configuration Item, the system should check whether it is a production CI or Non Production CI. If it is a Prod CI then it will go for CAB approval else it will bypass that approval and directly go to Schedule State.
So my approach to achieve this is as follows:
1. Use a if condition is workflow before CAB approval to check whether it is Prod Ci or Not.
2. In If Condtion, I am trying to get the sys_id of the Configuration Item on the Change form.
3. Then using that sys_id, I will find the table to which that value belongs.
4. Once this will be achieved, I will check if that table have used_for field, If yes then i will find the value in that field. If it will production then it will go to CAB Approval else if the field have any other value it will go to Schedule Step directly.
5. Also if the table do not have used_for field, then also it will directly go to Schedule State and do not require CAb approval.
I hope my approach is right, if not please do let me know how to achieve this.
Thanks & Regards,
Bhoomika

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 05:18 AM
Hi Bhoomika,
Thank you for the detail. In the future, you may want to provide that first.
You do not need to retrieve the entire record in this case. Use a feature called dot-walking to get the value of the field you need in the related table.
Something like this:
if (current.cmdb_ci) {
if (current.cmdb_ci.used_for == 'production') {
return 'yes'; // or 'true' or whatever
}
}
return 'no'; // or false
Reference: