- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2017 06:38 AM
Hi all,
I'm hoping someone can see what I'm doing wrong here. I am attempting to iterated through the xml field on the task_ci table to print the proposed CI changes in an approval email for Change Requests. I am trying to build a comma separated string of the current table and all parents so that I can look for the fields in the dictionary to grab some information.
This is the result I'm getting in my testing:
Sending string back: cmdb_ci_linux_server,cmdb_ci_server,cmdb_ci_computer,cmdb_ci_hardware,cmdb_ci,cmdb
tables: undefined
This is the call to the function from the main script (which is returning "undefined"):
var lookforTables = getParentTables(tableNodeName,tableNodeName);
template.print('tables: ' + lookforTables);
This is the function that shows that it will return the entire string of table names:
function getParentTables(table,string){
var newString = string;
var thisTable = new GlideRecord('sys_db_object');
thisTable.addQuery('name',table);
thisTable.query();
if(thisTable.next()){
if(thisTable.super_class){
newString += ',' + thisTable.super_class.name;
getParentTables(thisTable.super_class.name,newString);
}
else{
template.print('Sending string back: ' + newString);
return newString;
}
}
}
I'm not sure what's wrong...
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2017 08:56 PM
Can we try like,
var lookforTables = getParentTables(tableNodeName);
template.print('tables: ' + lookforTables);
function getParentTables(table){
var tablehierarchy = new TableUtils(table);
return tablehierarchy.getTables();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2017 06:26 PM
Hi,
I'm not sure if the line getParentTables(thisTable.super_class.name,newString); is gonna work.
but you can try using a try catch and log any error so you can see if your code is executing without errors.
You can also try a different approach.
var table='table name';
var tablenames=table;
var parent;
do {
parent=getParent(table);
if(parent)
{
tablenames+=','+parent;
table=parent;
}
}
while (parent);
function getParent(table) // not actual code, logic only
{
return table.parent
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2017 06:53 PM
can u try this
return 'sys_idIN' + newString;
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2017 08:56 PM
Can we try like,
var lookforTables = getParentTables(tableNodeName);
template.print('tables: ' + lookforTables);
function getParentTables(table){
var tablehierarchy = new TableUtils(table);
return tablehierarchy.getTables();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2017 06:17 AM
Thanks! This worked like a charm!