Auto Populate Affected CIs - Change Management

abhinav_khanna
Kilo Expert

Hi all,

This is an urgent requirement and I am unable to find a solution.

Query -

Based on the CI selected in the "cmdb_ci" field in the Change Request form, all the downstream and upstream CIs should auto populate in the Affected CI's related liste

Currently this functionality is through the BSM Map, where we have to go one by one and right click on the CI and the add the CI to the affected CIs.
I want to automate this whole process .
Kindly help me out with this one.

Regards
Abhinav Khanna

6 REPLIES 6

We worked around it . This was leading to an endless chain on linkage between CIs . Now the user has to access the BSM map and add the CIs manually


Hi Abhinav,

I came across your post as I was looking for a solution that would work well for me. I tried working with the proposed solution from ServiceNow Guru but could not get it to work quite right for me.

I ended up developing my own script and applied it to a Business Rule on the Change Management table. It seems to work well when looking specifically for 1 to 1 relationships mapped to the CI selected in the Change Record.... Which for us right now, is what the organization is looking for. 

Here is the Business Rule

Name: Auto Populate Affected CIs

Table: Change Request

Advanced: true

When: before

Insert: true

Update: true

Filter Condition: Configuration item Changes

Script: 

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

// Delete previously affected CI records for this task to address CI Change on Record
var rec = new GlideRecord('task_ci');
rec.addQuery('task', current.sys_id);
rec.addQuery('ci_item', '!=', previous.cmdb_ci); //addresses a validation issue with previous cmdb_ci when changed
rec.query();
while (rec.next())
rec.deleteRecord();

// Creating a query to pull on mapped relationships of the New Change CI
var gr = new GlideRecord('cmdb_rel_ci');
gr.addQuery('parent', current.cmdb_ci);
gr.query();

// When matched mapped CIs found and insert new record for the Affected CI related list.
while (gr.next()) {
var ci = new GlideRecord('task_ci');
ci.initialize();
ci.ci_item = gr.child;
ci.task = current.sys_id;
ci.insert();
}
})(current, previous);

 

Hopefully others can use it or at least build off of it. It is not as fancy as those script includes that are being used for CIUtils2 but it definitely works for me. 😃