- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-08-2020 12:31 PM
HI All,
I have a table which is extended from CMDB CI. There are also many custom fields created in the child table.
Does anyone have a way to fetch the list all the custom fields from the child table via script?. it should only give results of non extended fields belonging to the child. It a huge table so I cannot check fields one by one.
I have done this before but somehow unable to get hold of the script again.
Thanks
Shreyas
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-09-2020 07:40 PM
My bad. The script worked on extended tables in cmdb but seems like it doesn't for custom tables.
Fixed the script.
var tableName = 'u_test_extend';
var tableUtil = new TableUtils(tableName);
var parentTables = tableUtil.getTables().toArray();
parentTables.shift();
var parentColumns = [];
for (var i=0; i<parentTables.length; i++) {
var table = parentTables[i];
var grSysParent = new GlideRecord('sys_dictionary');
grSysParent.addEncodedQuery('name=' + table + '^internal_type!=collection^internal_typeISNOTEMPTY');
grSysParent.addOrderBy('column_label');
grSysParent.query();
while(grSysParent.next()) {
parentColumns.push(grSysParent.element.toString());
}
}
var grSysCustom = new GlideRecord('sys_dictionary');
grSysCustom.addEncodedQuery('name=' + tableName + '^internal_type!=collection^internal_typeISNOTEMPTY');
grSysCustom.addOrderBy('column_label');
grSysCustom.query();
var customTableColumns = [];
while(grSysCustom.next()) {
customTableColumns.push(grSysCustom.element.toString());
}
for (var j=0; j<parentColumns.length; j++) {
var x = customTableColumns.indexOf(parentColumns[j]);
if (x > -1) {
customTableColumns.splice(x,1);
}
}
gs.info(customTableColumns);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2022 05:38 AM
Very useful script :). Thank you Hitoshi