Auto Populate Impacted Services/CI's related list tab based on Affected CIs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2017 01:37 AM
Friends,
In Change Form, I am trying to auto populate Impacted Service/CI's related list Tabs based on Affected CI related list. This include all the 'auto' found CIs ( CI Selected during Change Submission)as well as the manually added CI's through affected CI tab. I have tried to configure it trough Display BR but its not working. Could you please someone help on this?
BR Info : On Display ( When record is inserted/updated with No Condition)
============================================================
(function executeRule(current, previous /*null when async*/) {
removeAffectedServices(); // First, search for all m2m records for the current task and delete if there are any
addAffectedServices(); // Use the CIUtils script include to find all related services to the CI selected in the task and add m2m records
function addAffectedServices() {
var ciu = new CIUtils();
var services = ciu.servicesAffectedByCI(current.cmdb_ci);
var m2m = new GlideRecord('task_cmdb_ci_service');
for (var i = 0; i < services.length; i++) {
m2m.initialize();
m2m.task = current.sys_id;
m2m.cmdb_ci_service = services[i];
m2m.manually_added = 'false';
m2m.insert();
}
}
function removeAffectedServices() {
var m2m = new GlideRecord('task_cmdb_ci_service');
m2m.addQuery('task',current.sys_id);
m2m.query();
m2m.deleteMultiple();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2017 12:57 AM
in the line: var services = ciu.servicesAffectedByCI(current.cmdb_ci);
what is the current.cmdb_ci?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2017 02:47 AM
Hi Suresh,
You are only taking the 'cmdb_ci' configuration item, while you should take all the affected CI's from the list.
Instead of having a display BR, you can have a UI action, which will do all the populating task on demand and will be performance friendly as well.
In UI action you can have code as below:
------------------------------------------------------
current.update();
action.setRedirectURL(current);
removeAffectedServices();
if (!current.cmdb_ci.nil())
addAffectedServices();
function removeAffectedServices() {
var m2m = new GlideRecord('task_cmdb_ci_service');
m2m.addQuery('task',current.sys_id);
m2m.addQuery('manually_added','false');
m2m.query();
m2m.deleteMultiple();
}
function addAffectedServices() {
var ciu = new CIUtils();
var arrUtil = new global.ArrayUtil();
var services = [];
// Get all the Affected CIs from the list
var gr = new GlideRecord('task_ci');
gr.addQuery('task', current.getUniqueValue());
gr.query();
// Concatenate all the services into an array
while (gr.next()) {
var arr = ciu.servicesAffectedByCI(gr.getValue('ci_item'));
services = services.concat(arr);
}
if (services.length > 0)
services = arrUtil.unique(services); // avoid duplicate entries
// Inset into the table
var m2m = new GlideRecord('task_cmdb_ci_service');
for (var i = 0; i < services.length; i++) {
m2m.initialize();
m2m.task = current.sys_id;
m2m.cmdb_ci_service = services[i];
m2m.manually_added = 'false';
m2m.insert();
}
}
----------------------------------------
Hope this helps.
Thanks,
Himanshu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2018 01:57 PM
So I have done this and activated the UI Action but my impacted service is still not populating? Could it be that I don't have the relationship set up correctly? I currently have the Business service depending on a software package. There are a lot of option to choose from for relationships but nothing I have found explains the relationships I need to set up and why?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2020 09:46 AM