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?
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
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) ~[?:?]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ram Kumar Aravindakshan _Adaptavist_
Here are the logs.
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) ~[?:?]
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) ~[?:?]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @Bill Sheboy - What do you think? Is this a candidate for lookup table with Automation for Jira?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @John Funk
I do not believe lookup tables have been implemented yet for the Data Center version of automation rules.
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.