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:04 AM
The code should be
(function executeRule(current, previous /*null when async*/) {
var tableName = current.cmdb_ci.sys_class_name;
gs.addInfoMessage(tableName);
})(current, previous);
You had current.cmdb.sys_class_name, not current.cmdb_ci.sys_class_name.
The other interesting part is that the line of code should only run once, yet you have multiple messages being displayed. That suggests the BR is being triggered multiple times which can be very inefficient. I recommend turning on Business Rule debugging to see when and why that business rule is being triggered.
See section 3.1.2 here
Debugging Tools Best Practices - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 06:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 05:09 AM
gs.addInfoMessage(current.cmdb_ci.getTableName())
Just Use this line.
Both sys_class_name and getTableName() are to get the table.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 04:05 AM
Reason its not working because both the sys_id's are different, you are using a particular record of cmdb_ci sys_id and comparing it with the table name cmdb_ci sys_id.
Thanks
Akhil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 04:15 AM
var gr = new GlideRecord('sys_db_object');// store all table info
gr.addQuery('sys_id',ci_sysid);// Here you are comparing table name sys id with table record sysid
Its not workout.
tell me your requirement more in detail.