Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Set Priority Using an Severity-Frequency Matrix

Lakshmi S
Contributor
June 12, 2024

Hi Team,

 I want to set priority using a severity-frequency matrix. 
For ex : If the "Severity" field value is "1-Critical" and "Frequency" field value is "High", the Priority field should be changed to "Blocker". 

I am trying with the below code, but its not working. Is there any reference for this kind of requirement?


matrix.png


 

import com.atlassian.jira.issue.IssueFieldConstants
import groovy.transform.BaseScript
import com.onresolve.jira.groovy.user.FieldBehaviours

@BaseScript FieldBehaviours fieldBehaviours

def priorityMatrix = [
    Blocker: [
        "1 - Critical"  : "1 - High"
       
    ],
    Critical    : [
       "1 - Critical"  : "2 - Medium"
    ]
   
def priorityField = getFieldById(IssueFieldConstants.PRIORITY)

def severityFieldValue = getFieldByName('Severity').value as String
def frequencyFieldValue = getFieldByName('Frequency').value as String

def priority = priorityMatrix[frequencyFieldValue][severityFieldValue]
priorityField.setFormValue(priority)

2 answers

Suggest an answer

Log in or Sign up to answer
1 vote
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 12, 2024

Hi @Lakshmi S

Please clarify: Do you intend the priority to change based on the values of both the Severity and Frequency fields?

If yes, then your current approach will not work. You must create two separate Server-Side Behaviours: one for the Severity field and one for the Frequency field.

Below are the Server-Side Behaviour configurations:-

1. For the Severity field:-

import static com.atlassian.jira.issue.IssueFieldConstants.PRIORITY
import groovy.transform.BaseScript
import com.onresolve.jira.groovy.user.FieldBehaviours

@BaseScript FieldBehaviours fieldBehaviours

def priorityMatrix = [
Blocker: ["1 - Critical":"1 - High" ],
Critical: ["1 - Critical":"2 - Medium" ]
]

def priorityField = getFieldById(PRIORITY)

def severityField = getFieldById(fieldChanged)
def severityFieldValue = severityField.value.toString()

def frequencyField = getFieldByName('Frequency')
def frequencyFieldValue = frequencyField.value.toString()

def priority = priorityMatrix[frequencyFieldValue][severityFieldValue]

priorityField.setFormValue(priority)

2. For the Frequency field:-

import static com.atlassian.jira.issue.IssueFieldConstants.PRIORITY
import groovy.transform.BaseScript
import com.onresolve.jira.groovy.user.FieldBehaviours

@BaseScript FieldBehaviours fieldBehaviours

def priorityMatrix = [
Blocker: ["1 - Critical":"1 - High" ],
Critical: ["1 - Critical":"2 - Medium" ]
]

def priorityField = getFieldById(PRIORITY)

def severityField = getFieldByName('Severity')
def severityFieldValue = severityField.value.toString()

def frequencyField = getFieldById(fieldChanged)
def frequencyFieldValue = frequencyField.value.toString()

def priority = priorityMatrix[frequencyFieldValue][severityFieldValue]

priorityField.setFormValue(priority)

Please make the required modifications and let me know how it goes.

Thank you and Kind regards,
Ram

Lakshmi S
Contributor
June 13, 2024

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

 

 Thank you for the quick response Ram!. Yes, I want to change the priority field based on these two fields "Severity" and "Frequency"

I added the two server scripts, but its not working. and see the error in the logs, and Please check the attached screenshots for your refernce.



2024-06-13T17:29:26,451 ERROR [behaviours.BehaviourManagerImpl]: *************************************************************************************
2024-06-13T17:29:26,452 ERROR [behaviours.BehaviourManagerImpl]: Script function failed on issue: (create issue) project/issuetype: TEST/Task, fieldId: customfield_34215, file: <inline script>, edit behaviour: plugins/servlet/scriptrunner/admin/behaviours/edit/4ccd5671-4e5a-4459-b313-ee75019cf021
java.lang.NullPointerException: Cannot get property '1 - Critical' on null object
at a8ade8bae77a6f0ae48bec5ea92e937a.run(a8ade8bae77a6f0ae48bec5ea92e937a.groovy:20) ~[?:?]

severity.pngfrequency.png

 

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 14, 2024

Hi Lakshmi,

It seems like it needs both values to be selected before it can run. 

Please add the condition to your code:-

if(frequencyFieldValue && severityFieldValue) {


}

For the Severity field:-

import static com.atlassian.jira.issue.IssueFieldConstants.PRIORITY
import groovy.transform.BaseScript
import com.onresolve.jira.groovy.user.FieldBehaviours

@BaseScript FieldBehaviours fieldBehaviours

def priorityMatrix = [
Blocker: ["1 - Critical":"1 - High" ],
Critical: ["1 - Critical":"2 - Medium" ]
]

def priorityField = getFieldById(PRIORITY)

def severityField = getFieldById(fieldChanged)
def severityFieldValue = severityField.value.toString()

def frequencyField = getFieldByName('Frequency')
def frequencyFieldValue = frequencyField.value.toString()

if(frequencyFieldValue && severityFieldValue) {

def priority = priorityMatrix[frequencyFieldValue][severityFieldValue]
priorityField.setFormValue(priority)
}

For the Frequency field:-

import static com.atlassian.jira.issue.IssueFieldConstants.PRIORITY
import groovy.transform.BaseScript
import com.onresolve.jira.groovy.user.FieldBehaviours

@BaseScript FieldBehaviours fieldBehaviours

def priorityMatrix = [
Blocker: ["1 - Critical":"1 - High" ],
Critical: ["1 - Critical":"2 - Medium" ]
]

def priorityField = getFieldById(PRIORITY)

def severityField = getFieldByName('Severity')
def severityFieldValue = severityField.value.toString()

def frequencyField = getFieldById(fieldChanged)
def frequencyFieldValue = frequencyField.value.toString()

if (frequencyFieldValue && severityFieldValue) {

def priority = priorityMatrix[frequencyFieldValue][severityFieldValue]
priorityField.setFormValue(priority)

}

I hope this helps to solve your question. :-)

Thank you and Kind regards,
Ram

Lakshmi S
Contributor
June 14, 2024

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

 Sorry, I didn't see the comment under your suggested answer. Yes, I am filling up both fields before creating the ticket, but it's not working with your new suggested code either. Its showing same error in the logs.

code.png

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 17, 2024

Hi @Lakshmi S

Could you please print some log output to see if the condition is even being reached:-

For the Severity field:-

import static com.atlassian.jira.issue.IssueFieldConstants.PRIORITY
import groovy.transform.BaseScript
import com.onresolve.jira.groovy.user.FieldBehaviours

@BaseScript FieldBehaviours fieldBehaviours

def priorityMatrix = [
Blocker: ["1 - Critical":"1 - High" ],
Critical: ["1 - Critical":"2 - Medium" ]
]

def priorityField = getFieldById(PRIORITY)

def severityField = getFieldById(fieldChanged)
def severityFieldValue = severityField.value.toString()

def frequencyField = getFieldByName('Frequency')
def frequencyFieldValue = frequencyField.value.toString()

log.warn "===============<<<<>>>> Priority Value: ${priorityField.formValue}"

if(frequencyFieldValue && severityFieldValue) {
log.warn "======================>>>>> Severity Value: ${severityFieldValue}"
log.warn "======================<<<<< Frequency Value ${frequencyFieldValue}"

def priority = priorityMatrix[frequencyFieldValue][severityFieldValue]
priorityField.setFormValue(priority)
}

and for the Frequency field:-

import static com.atlassian.jira.issue.IssueFieldConstants.PRIORITY
import groovy.transform.BaseScript
import com.onresolve.jira.groovy.user.FieldBehaviours

@BaseScript FieldBehaviours fieldBehaviours

def priorityMatrix = [
Blocker: ["1 - Critical":"1 - High" ],
Critical: ["1 - Critical":"2 - Medium" ]
]

def priorityField = getFieldById(PRIORITY)

def severityField = getFieldByName('Severity')
def severityFieldValue = severityField.value.toString()

def frequencyField = getFieldById(fieldChanged)
def frequencyFieldValue = frequencyField.value.toString()

log.warn "===============<<<<>>>> Priority Value: ${priorityField.formValue}"

if (frequencyFieldValue && severityFieldValue) {
log.warn "======================>>>>> Severity Value: ${severityFieldValue}"
log.warn "======================<<<<< Frequency Value ${frequencyFieldValue}"

def priority = priorityMatrix[frequencyFieldValue][severityFieldValue]
priorityField.setFormValue(priority)

}

Please share the log output that is being returned for the marked logs.

Thank you and Kind regards,
Ram

 

Lakshmi S
Contributor
June 17, 2024

Hi @Ram Kumar Aravindakshan _Adaptavist_ 

 

Here are the logs.

Severity :

2024-06-17T14:08:06,545 WARN [runner.ScriptBindingsManager]: ===============<<<<>>>> Priority Value: 4

2024-06-17T14:08:06,545 WARN [runner.ScriptBindingsManager]: ======================>>>>> Severity Value: 1 - Critical

2024-06-17T14:08:06,545 WARN [runner.ScriptBindingsManager]: ======================<<<<< Frequency Value null

2024-06-17T14:08:06,546 ERROR [behaviours.BehaviourManagerImpl]: *************************************************************************************

2024-06-17T14:08:06,548 ERROR [behaviours.BehaviourManagerImpl]: Script function failed on issue: (create issue) project/issuetype: TEST/Task,  fieldId: customfield_16003, file: <inline script>, edit behaviour: /plugins/servlet/scriptrunner/admin/behaviours/edit/4ccd5671-4e5a-4459-b313-ee75019cf021

java.lang.NullPointerException: Cannot get property '1 - Critical' on null object

at 4e6133b063a53bf811d4d685bf246b7d.run(4e6133b063a53bf811d4d685bf246b7d.groovy:26) ~[?:?]

Frequency :

2024-06-17T14:08:08,284 WARN [runner.ScriptBindingsManager]: ===============<<<<>>>> Priority Value: 4

2024-06-17T14:08:08,284 WARN [runner.ScriptBindingsManager]: ======================>>>>> Severity Value: 1 - Critical

2024-06-17T14:08:08,284 WARN [runner.ScriptBindingsManager]: ======================<<<<< Frequency Value 1 - High

2024-06-17T14:08:08,285 ERROR [behaviours.BehaviourManagerImpl]: *************************************************************************************

2024-06-17T14:08:08,286 ERROR [behaviours.BehaviourManagerImpl]: Script function failed on issue: (create issue) project/issuetype: TEST/Task, fieldId: customfield_34215, file: <inline script>, edit behaviour: /plugins/servlet/scriptrunner/admin/behaviours/edit/4ccd5671-4e5a-4459-b313-ee75019cf021

java.lang.NullPointerException: Cannot get property '1 - Critical' on null object

at 3c7c29f2e499144b8b79eed72064c20d.run(3c7c29f2e499144b8b79eed72064c20d.groovy:26) ~[?:?]

 

Like John Funk likes this
0 votes
John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 6, 2024

Hey @Bill Sheboy  - What do you think? Is this a candidate for lookup table with Automation for Jira? 

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 6, 2024

Hi @John Funk 

I do not believe lookup tables have been implemented yet for the Data Center version of automation rules.

Kind regards,
Bill

Like John Funk likes this
TAGS
AUG Leaders

Atlassian Community Events