Automatically update the priority of an issue based on the value urgency and impact.

Hi,

 

I found alot of information already but i can not get things to work. What I am trying to achieve is that when the Urgency of impact is changed, the priority is seat to the proper value. When a user saves the issue, priority should be stored as well.

I created a scripted field and I can show the desired values in this field. And it behaves exactly how I want it to behave. Next step is to check if I can update the priority as well just as described. When this works the scripted field will be hidden for regular users.

I am aware that I can use a post script as well, but this is not always going to update the priority just like the standaard automation in JIRA servicedesk. So that always can cause wrong interpretations.

The code I am using is shown below. Am I missing something? Is it possible?

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.MutableIssue

// This is a two dimensional map to represent the matrix
// Keys along left is urgency and second dimension keys is the impact
def priorityMatrix = [
    Cosmetisch: ["0..1 Gebruikers": "5", "2..5 Gebruikers": "5", "5+ Gebruikers": "4"],
    Hinderlijk: ["0..1 Gebruikers": "5", "2..5 Gebruikers": "4", "5+ Gebruikers": "3"],
    Blokkerend: ["0..1 Gebruikers": "4", "2..5 Gebruikers": "3", "5+ Gebruikers": "7"],
]
 
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def constantsManager = ComponentAccessor.getConstantsManager()
def issueService = ComponentAccessor.getIssueService()
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()
 
//def issue = issue as Issue
 
def urgencyField = customFieldManager.getCustomFieldObjectByName("Urgency")
 
def impactField = customFieldManager.getCustomFieldObjectByName("Impact")
 
def urgency = issue.getCustomFieldValue(urgencyField) as Option
def impact = issue.getCustomFieldValue(impactField) as Option
 
String priorityName = priorityMatrix[urgency.value][impact.value]
String issuetype = issue.issueTypeObject.name
def MutableIssue mutableIssue = (MutableIssue) issue
if (issuetype == "Incident") {
    
    return priorityName
    mutableIssue.setPriorityId(priorityName)
 
}

2 answers

This widget could not be displayed.
Gaston Valente Community Champion Mar 07, 2017

Hi,

You can try to call the store() method after setting the priority, but it's recommended to use the issueservice as described here:

https://developer.atlassian.com/jiradev/jira-platform/guides/issues/guide-performing-issue-operations

Hope it helps

Gaston Valente Community Champion Mar 07, 2017

i think that you need to move the return statment to the bottom of the code too

This widget could not be displayed.

Thanks, I will look into that.

Meanwhile i will post this question tot the proper forum (adaptavist).

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

523 views 3 19
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you