How to automate the manual process to add a related list tab to a cmdb classes

VS M
Kilo Guru

Hello Experts,

 

I am familiar with manual process (Navigate to Default view of Form > Configure > Related List > Slush bucket > Click "Save"). I have a need to add a Affected by task related tab to almost all CMDB CI classes.

 

I came up with below script to automate this process, works fine up to related list entry record insertion but it does not show up in actual form and when I navigate to Configure > Related List > Slush bucket it shows up there. Surprisingly, it works when I click SAVE.

 

var rList = new GlideRecord('sys_ui_related_list');
rList.addQuery('view', 'STARTSWITH'', 'Default view');
rList.addQuery('name', 'STARTSWITH', 'cmdb_ci_');
rList.query();

while (rList.next()) {
    var rListEntry = new GlideRecord('sys_ui_related_list_entry');
    rListEntry.initialize();
    rListEntry.related_list = "task_ci.ci_item"; // Affected by Task
    rListEntry.list_id = rList.sys_id;
    rListEntry.insert();
}

 

 

Thanks for responding to this question.

 

1 ACCEPTED SOLUTION

VS M
Kilo Guru

Script worked, after switching the query to calculated_name (related list), and adding a order to related list entry.

View solution in original post

2 REPLIES 2

Marco0o1
Tera Sage

Hi @VS M :

You can just add a business rule on insert from your record:

Marco0o1_0-1691015698782.png

You can add some conditions when is runn, and in the advanced tab:

Marco0o1_1-1691015751473.png

You can add some condition like validate any field or any role and put your code:

(function executeRule(current, previous /*null when async*/) {

var rList = new GlideRecord('sys_ui_related_list');
rList.addQuery('view', 'STARTSWITH', 'Default view');
rList.addQuery('name', 'STARTSWITH', 'cmdb_ci_');
rList.query();

while (rList.next()) {
    var rListEntry = new GlideRecord('sys_ui_related_list_entry');
    rListEntry.initialize();
    rListEntry.related_list = current.ci_item; // Affected by Task [There is the change from your code]
    rListEntry.list_id = rList.sys_id;
    rListEntry.insert();
}

})(current, previous);

That is what i understand, if you have any issue you can share more about when is you action is executed, you can try with a flow in flow designer but you will need to make the code again. Hope that help you.

VS M
Kilo Guru

Script worked, after switching the query to calculated_name (related list), and adding a order to related list entry.