- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2023 03:05 PM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2023 10:38 AM
Script worked, after switching the query to calculated_name (related list), and adding a order to related list entry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2023 03:37 PM
Hi @VS M :
You can just add a business rule on insert from your record:
You can add some conditions when is runn, and in the advanced tab:
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2023 10:38 AM
Script worked, after switching the query to calculated_name (related list), and adding a order to related list entry.