I want to set a custom field value "Risk Score" based on the user selected values in 2 single select custom fields, "Impact" and "Probability".
I've tried two different ways to address this based on other articles, but my approaches are not working. When I'm in the create issue screen, after I've set the value for both Impact and Probability, the risk score does not update. Any advice??
Approach 1 (based on Adaptavist Article on Set Priority Using an Impact-Urgent matrix)
def riskMatrix = [
"Critical (20-25)" : [
"5 - Highly Likely": "5 - High",
"5 - High": "5 - Highly Likely",
"5 - Highly Likely": "4 - Moderate",
"4 - Likely": "5 - High"
],
"Mid (10-19)" : [
"5 - Highly Likely": "3 - Low",
"5 - Highly Likely": "2 - Annoyance",
"4 - Likely": "3 - Low",
"4 - Likely": "4 - Moderate",
"3 - Possible": "5 - High",
"3 - Possible": "4 - Moderate",
"2 - Unlikely": "5 - High"
],
"Low (1-9)" : [
"5 - Highly Likely": "1 - No Effect",
"4 - Likely": "1 - No Effect",
"3 - Possible": "1 - No Effect",
"2 - Unlikely": "1 - No Effect",
"1 - Highly Unlikely": "1 - No Effect",
"4 - Likely": "2 - Annoyance",
"3 - Possible": "2 - Annoyance",
"2 - Unlikely": "2 - Annoyance",
"1 - Highly Unlikely": "2 - Annoyance",
"3 - Possible": "3 - Low",
"2 - Unlikely": "3 - Low",
"1 - Highly Unlikely": "3 - Low",
"2 - Unlikely": "4 - Moderate",
"1 - Highly Unlikely": "4 - Moderate",
"1 - Highly Unlikely": "5 - High",
]
]
def riskScoreField = getFieldById ("customfield_15704") //("Risk Score") //customfield_15704
def impactFieldValue = getFieldByName("Impact (Freestyle)").value //customfield_15709
def probabilityFieldValue = getFieldByName("Probability").value //customfield_15708
String riskScore = riskMatrix[probabilityFieldValue][impactFieldValue]
riskScoreField.setFormValue(riskScore)
Approach 2: based on https://community.atlassian.com/t5/Jira-questions/Behaviour-Plugin-Setting-Priority-based-on-value-in-a-Scripted/qaq-p/180062
def fimpact = getFieldByName("Impact (Freestyle)")
def fprobability = getFieldByName("Probability")
def friskscore = getFieldById("customfield_15704") //Risk Score
String Impact = (String) fimpact.getFormValue()
String Probability = (String) fprobability.getFormValue()
if (Impact == "5 - High" && Probability == "5 - Highly Likely") {
friskscore.setFormValue("Critical (20-25)")
} else if (Impact == "5 - High" && Probability == "4 - Likely") {
friskscore.setFormValue("Critical (20-25)")
} else if (Impact == "4 - Moderate" && Probability == "5 - Highly Likely") {
friskscore.setFormValue("Critical (20-25)")
} else if (Impact == "5 - High" && Probability == "2 - Unlikely") {
friskscore.setFormValue("Mid (10-19)")
} else if (Impact == "5 - High" && Probability == "1 - Highly Unlikely") {
friskscore.setFormValue("Low (1-9)")
Behaviours Config
In both cases, I've added a Server Side script to the Risk Score field.
