Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Bulk add related list to all CMDB Class forms

Tim Hannah
Tera Contributor

I have created a table called Device Health Check (u_device_health_check) which extends from task. it stores health check tasks for devices in the CMDB. 

I want to add this as a related list to ALL the CMDB class forms, so cmdb_ci_app_server, cmdb_ci_app_server_java, cmdb_ci_firewall_network etc etc 

Is there a quick way of doing this using a background script? 

1 ACCEPTED SOLUTION

Naveen20
ServiceNow Employee
ServiceNow Employee

You have to add entries to sys_ui_related_list_entry table after getting list id's of the default views of tables that start with cmdb_ci. Get the list id and populate the sys_ui_related_list_entry

This script should help. 


var rel = new GlideRecord('sys_ui_related_list');
rel.addQuery('calculated_name','ENDSWITH','Default view');
rel.addQuery('name','STARTSWITH','cmdb_ci');
rel.query();


while(rel.next()) {
var entry = new GlideRecord('sys_ui_related_list_entry');
entry.initialize();
entry.list_id = rel.sys_id;
entry.filter = // add the new table and column here. check existing ones for reference
entry.insert();
}

View solution in original post

1 REPLY 1

Naveen20
ServiceNow Employee
ServiceNow Employee

You have to add entries to sys_ui_related_list_entry table after getting list id's of the default views of tables that start with cmdb_ci. Get the list id and populate the sys_ui_related_list_entry

This script should help. 


var rel = new GlideRecord('sys_ui_related_list');
rel.addQuery('calculated_name','ENDSWITH','Default view');
rel.addQuery('name','STARTSWITH','cmdb_ci');
rel.query();


while(rel.next()) {
var entry = new GlideRecord('sys_ui_related_list_entry');
entry.initialize();
entry.list_id = rel.sys_id;
entry.filter = // add the new table and column here. check existing ones for reference
entry.insert();
}