How to get list of custom fields related to child table by omitting the inherited fields from parent table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2022 01:43 AM
Hi,
I have few extended tables from cmdb_ci. And few tables were again extended from these extended tables.
I want to get the list of fields that are specifically created on child table along with its Label, table name and its type. I don't want the repetition of fields in list. How to achieve it?
I have gone through CI class manager, and in attributes section I have found All, Derived, Added buttons. When I click on add button, it only showing the attributes specifically related to that class. Can't we use the same logic to achieve the above thing?
Thanks in Advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2022 03:25 AM
Hi Ajay,
In this scenario, Table Utils is the friend which you can use to get to your requirement.
Below script I have tested against Server table and it is giving me the list of Fields for all child or extended tables it has:
var table = new TableUtils("cmdb_ci_server");
gs.print(table.getHierarchy());
var childFields = getChildTableFields(table.getHierarchy());
function getChildTableFields(tableName){
var gr = new GlideRecord('sys_dictionary');
gr.addQuery('name',tableName);
gr.query();
while(gr.next()){
gs.info(gr.column_label + ' -' + gr.element);
}
}
Link for Table Utils below for reference:
https://developer.servicenow.com/print_page.do?release=Paris&category=null&identifier=c_TableUtilsAPI&module=api
Result:
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2022 03:53 AM
Hi
Thank you. With the script you provided, we are getting all the fields including parent table fields. But the thing I want is,
for suppose I have a field u_test_parent on cmdb_ci table.
And I have a field u_test_child on custom table u_test_ci (extended from cmdb_ci). As this table got extended from cmdb_ci, u_test_parent field will also visible on this table. But I need to get only u_test_child field, as this field is related specifically to u_test_ci table. I don't want to get the fields that are inherited from parents. Hope you got my point.
Here is the example, where u_test_parent is showing on all the tables extended from cmdb_ci.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2022 04:32 AM
Hi,
I do not think that will be possible. Reason being when you create a new table and say it is extended from any of the parent table, ServiceNow by default create the column entry for that new table as well which is coming from Parent when you extend an table and there is no way as far as I know you can filter like the way you need.
So for example, I created a New table which is extendable from Computer so now Assigned to is a attribute which is coming from computer but if you see the dictionary of Assigned to , a new entry got created for the new custom table I have created as shown below:
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke