Is it possible to filter affected and impacted CIs in a change record based on their relationship type?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2018 01:57 AM
We have a requirement to populate all upstream relationships in the Affected and Impacted CIs on change requests based on their relationship type.
We are using three relationships: Depends on::Used by, Used By::Uses, and Used::Used By.
We can get (using CIUtils) all upstream CIs to add in to both lists. However, we want the Affected CIs list to show the CI the change is being performed on and any CIs in the hierarchy which have a Depends On::Used By relationship to it. However, this might not be a direct relationship, so could be a few steps up in the hierarchy.
Impacted Cis should contain related upstream CIs which don't have the Depends On::Used By relationship.
The aim is to drive approvals for Affected CIs with the Depends On relationship, and information only notifications for the impacted (I think this should be the easy bit if we can get the filters to work...).
Any ideas?
- Labels:
-
Change Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2018 02:17 AM
Hi Nick,
You can do this by querying the cmdb_rel_ci table, you can build the query using the sys_id of the relationship you want to include/exclude and use that to populate an array with the parent or child in the relationship (depending on how the relationship is set up. Then you can use that array to populate the affected CI's table.
Cheers
Dave
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2018 02:44 AM
Thanks Dave,
So, we've got the following added in to the script include (for affected CIs):
var rel = new GlideRecord('cmdb_rel_ci');
rel.addQuery('child', id);
//only include relationship type: Depends on::Used by;
rel.addQuery('type', '1a9cb166f1571100a92eb60da2bce5c5');
rel.query();
gs.log(rel);
Which does filter the record. However, it isn't looping through to find all the parents, or grandparents. - As an example, We've got a server record, which has a parent with a used by relationship, then that CI's parent has a depends on relationship, but because there is no direct depend on relationship to the server, it doesn't find the 'grand' parent record. - As a result, only the server record is shown in the affected CI list (if I comment out the relationship part of the query, all upstream CIs are listed, so I have tried using a business rule to filter out any upstream parents which don't have the depends on relationship, but nothing seems to work.
My scripting skills aren't the best, so I'm a bit stumped. Any ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2018 03:17 AM
Hi Nick,
If you know how many level you're going to have to go you could nest some while loops to iterate through the immediate parents and the relationships to them and the relationships to the grandparents etc etc. if you don't know how many levels you might have to go you'll be better off writing a function that will iterate through x amount of levels for you until it finds no more entries. I don't really have time to write said function for you and, tbh, it made my brain hurt a bit when i started thinking about it but the nested while loops would look something like:
var arr = [];
var rel = new GlideRecord('cmdb_rel_ci');
rel.addQuery('child', id);
//only include relationship type: Depends on::Used by;
rel.addQuery('type', '1a9cb166f1571100a92eb60da2bce5c5');
rel.query();
gs.log(rel);
while(rel.next()){
var parent = gr.getValue('parent');
arr.push(parent);
var gr = new GlideRecord('cmdb_rel_ci');
gr.addQuery('child', parent);
gr.addQuery('type', '1a9cb166f1571100a92eb60da2bce5c5');
gr.query();
while(gr.next()){
var grandParent = gr.getValue('parent');
arr.push(grandParent);
var gr1 = new GlideRecord('cmdb_rel_ci');
gr1.addQuery('child', parent);
gr1.addQuery('type', '1a9cb166f1571100a92eb60da2bce5c5');
gr1.query();
//etc etc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2018 04:57 AM
Thanks again Dave,
This is helpful. 🙂