Only one matching risk condition is applying, is that expected?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2015 12:21 PM
I created a Business Service called "Blah" and then associated some CI's to that business service. I now go create a new Change Request, set the date for about an hour for now and pick a CI that is tied to the new business service. When I click the "Take Risk Assessment" link I get asked the questions and press submit. I now click "Execute Risk Calculation" to give me the risk and impact. The risk assessment portion appears to work properly and then gets over-written immediately because the Planned Start Date is so close… anything under 24 hours per my rule says that I have insufficient lead time which sets my risk to Very High. So far so good… but the risk conditions appear to stop there. If they rules would continue to process in order I would then also adjust my Impact because my business service sets the impact to 1 — very critical. That's not happening because my first rule was hit (insufficient lead time). If I re-order the risk conditions then I get the higher impact (mission critical service) but don't get the very high risk (insufficient lead time)… it seems to only process whatever the first risk condition is that it matches instead of all of them.
The problem I will ultimately run into here is that I need to set both risk and impact based on the assessment and various conditions (is the CI being changed part of a mission critical service? Etc). If the rules don't all run properly then I won't get the desired result (with both risk and impact being set). Any thoughts?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2015 08:58 PM
It looks like the RiskCalculator script include does indeed stop processing once it finds a match in the risk conditions. In Fuji at least, on line 23 of the RiskCalculator script include you'll see:
while(rc.next() && !match){
You could remove the && !match from that. That would have all of the risk conditions apply though, so in the out of the box risk conditions that means it sets the Risk and Impact to Low because it matches the 'default' Risk Condition.
Instead, I made some modifications to the RiskCalculator script include and was able to get it to iterate through risk condition matches until it has found a value for both Risk and Impact. So if it finds a Risk Condition at order 100 that sets the Risk Very High but doesn't set the Impact it will continue to go through the Risk Conditions and if it finds one at order 200 that sets the Impact High it will set that as well.
My updates RiskCalculator Script Include is:
var RiskCalculator = Class.create();
RiskCalculator.prototype = {
initialize : function(cr) {
this.riskRecord = cr;
this.riskList = this.getRiskList();
},
calculateRisk : function() {
if (!this.riskList.hasValue)
return "";
return this.riskList;
},
getRiskList : function() {
var riskList = new Object();
var match = false;
var riskMatch = false;
var impactMatch = false;
var rc = new GlideRecord('risk_conditions');
rc.addActiveQuery();
rc.orderBy("order");
rc.query();
while(rc.next()){
if(rc.use_advanced_condition)
match = GlideRhinoHelper.evaluateAsBoolean(rc.advanced_condition);
else {
var filter = GlideFilter;
match = filter.checkRecord(this.riskRecord, rc.condition);
}
if (match) {
riskList.hasValue = true;
riskList.name = rc.name + '';
riskList.order = rc.order + 0;
riskList.description = rc.description + '';
if (rc.use_script_values) {
var prevRisk = current.risk + '';
var prevImpact = current.impact + '';
GlideRhinoHelper.evaluateAsString(rc.script_values);
riskList.useScriptValues = true;
if (prevRisk != current.risk + '' && !riskMatch) {
riskList.risk = current.risk + '';
riskList.label = current.risk.getDisplayValue() + '';
}
if (prevImpact != current.impact + '' && !impactMatch) {
riskList.impact = current.impact + '';
riskList.impactLabel = current.impact.getDisplayValue() + '';
}
} else {
riskList.useScriptValues = false;
if (!riskMatch){
riskList.risk = rc.risk + '';
riskList.label = rc.risk.getDisplayValue() + '';
}
if (!impactMatch){
riskList.impact = rc.impact + '';
riskList.impactLabel = rc.impact.getDisplayValue() + '';
}
}
if (rc.risk!='')
riskMatch=true;
if (rc.impact!='')
impactMatch=true;
}
}
if (!match)
gs.addInfoMessage("No matching Risk Conditions - Risk and Impact unchanged");
return riskList;
},
type: 'RiskCalculator'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2015 05:38 AM
This is exactly where I was hoping this would go. With your code, are you looking for whatever the highest match is and then setting that? Or are you simply looking for a match?
For example, you're right... it will match on Default which sets Low/Low. It may have also matched on Insufficient Time which sets Risk to Very High. There are two different things trying to set the risk... how do you catch the one that has the highest value? If I can get that behavior to happen (cycle through all rules and simply select the highest value for any matching rule) then I think I have the intended behavior. Do you know what code change would be required to make that happen? I don't have the coding background to make that change so I really appreciate your help.
Andy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2015 07:39 AM
With the modification that I provided it's just pulling them in order based on the Order field of the Risk Conditions and once it finds a rule that sets the Risk it doesn't change it again after that. Same for Impact, once it has set the Impact it won't change it again.
So that really only works if the highest risk/impact have the highest order. I'll take another look at it to see about having it cycle through all matches and picking out the highest Risk and Impact.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2015 09:36 PM
Okay, I think I've got it working now where it takes the highest Risk and highest Impact of any risk conditions that it matches and utilizes those.
var RiskCalculator = Class.create();
RiskCalculator.prototype = {
initialize : function(cr) {
this.riskRecord = cr;
this.riskList = this.getRiskList();
},
calculateRisk : function() {
if (!this.riskList.hasValue)
return "";
return this.riskList;
},
getRiskList : function() {
var riskList = new Object();
var match = false;
var rc = new GlideRecord('risk_conditions');
rc.addActiveQuery();
rc.orderBy("order");
rc.query();
while(rc.next()){
if(rc.use_advanced_condition)
match = GlideRhinoHelper.evaluateAsBoolean(rc.advanced_condition);
else {
var filter = GlideFilter;
match = filter.checkRecord(this.riskRecord, rc.condition);
}
if (match) {
msg+='\nRisk condition: ' + rc.name + '\n';
riskList.hasValue = true;
riskList.name = rc.name + '';
riskList.order = rc.order + 0;
riskList.description = rc.description + '';
if (rc.use_script_values) {
var prevRisk = current.risk + '';
var prevImpact = current.impact + '';
GlideRhinoHelper.evaluateAsString(rc.script_values);
riskList.useScriptValues = true;
if (prevRisk != current.risk + '' && current.risk < prevRisk) {
riskList.risk = current.risk + '';
riskList.label = current.risk.getDisplayValue() + '';
}
if (prevImpact != current.impact + '' && current.imapct < prevImpact) {
riskList.impact = current.impact + '';
riskList.impactLabel = current.impact.getDisplayValue() + '';
}
} else {
riskList.useScriptValues = false;
if (riskList.impact=='' || riskList.impact == undefined || riskList.impact > rc.impact){
riskList.impact = rc.impact + '';
riskList.impactLabel = rc.impact.getDisplayValue() + '';
}
if (riskList.risk=='' || riskList.risk == undefined || riskList.risk > rc.risk){
riskList.risk = rc.risk + '';
riskList.label = rc.risk.getDisplayValue() + '';
}
}
}
}
if (!match)
gs.addInfoMessage("No matching Risk Conditions - Risk and Impact unchanged");
return riskList;
},
type: 'RiskCalculator'
};