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 03:56 AM
If it's just CI's then you can use current.cmdb_ci.sys_class_name to get the table name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 04:55 AM
Hi Geoffrey,
I tried the code you mentioned above as :
(function executeRule(current, previous /*null when async*/) {
var tableName = current.cmdb_ci.sys_class_name;
gs.addInfoMessage(tableName);
})(current, previous);
And I got this :
It's not working
Please review & let me know.
Thanks & Regards,
Bhoomika

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 03:57 AM
If you have a reference to the sys_id, then you should also have a table name with
var tableName = current.cmdb.sys_class_name;
No need to query every table on the system to find out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 04:59 AM
Hi Chuck,
I modified the code as per your suggestion :
(function executeRule(current, previous /*null when async*/) {
var tableName = current.cmdb.sys_class_name;
gs.addInfoMessage(tableName);
})(current, previous);
And below is the result:
I am not able to get the table name
Please review and let me know.
Thanks & Regards,
Bhoomika