Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to set different default Priority between different issue types in the same project?

Diana
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.
November 17, 2022

Since I can only use 1 Priority Scheme per project, is there a way using Scriptrunner to set different default priorities based on issue type?

We use Feature and stories for basic priority (Top, High Medium, Low) but our project also uses Bug issue type with it's own priorities (Pri 1, Pri 2, Pri 3, Pri 4, Pri 5).

Medium is set as default for the project, but is there a way in our Bug's workflow post-function to Create to make the priority default set to Pri 3? 

import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.config.PriorityManager
import com.atlassian.jira.component.ComponentAccessor
import static com.atlassian.jira.issue.IssueFieldConstants.*

def field = ComponentAccessor.getComponent(PriorityManager).priorities
def defaultPri = ComponentAccessor.getConstantsManager().getPriorities().find {it.getName().equals("Medium")}.getId()
def priThree = ComponentAccessor.getConstantsManager().getPriorities().find {it.getName().equals("Pri 3")}.getId()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

if (field == defaultPri || field == null){
   issue.setPriorityId(priThree)
}


ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)

In addition, I have a Behaviors script that sets the Priority option for Bugs to only be Pri1-Pri5, so every time I create a Bug, priority becomes empty if I don't select anything. Ideally, would want it to be Pri 3 is nothing was selected.

1 answer

1 accepted

1 vote
Answer accepted
Alex Koxaras -Relational-
Community Champion
November 17, 2022

Hi @Diana Gorv 

I wouldn't create a script for this. I would place PFs inside each issue type's workflow and define its priority from there.

Diana
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.
November 17, 2022

Hi @Alex Koxaras -Relational- Thank you for the quick response!

That could work. But if I use "Update Issue Field" as a post function, and have Priority set to Pri 3, if a user wants to create a Bug that's a Pri 5, that post-function will auto set it to Pri 3. In that case, I would want the user to still be able to set their priority if they have one. 

Is there a way issue types in a project can have different default priorities out-of-the box? If not, is there a way for my script can catch if a user creates a Bug, did not select a priority, then the newly created Bug is set to priority Pri 3?

Alex Koxaras -Relational-
Community Champion
November 17, 2022

If you have an app like JMWE, it offers the possibility to run a PF, if a certain condition is met - in your case, set the priority only if it's empty.

With scriptrunner you can do of course the same thing. It's doable, as long as you write the script and have the condition that the priority is empty.

Diana
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.
November 17, 2022

Wouldn't the script I have above meet that criteria though? Am I defining the priority field and it's values correctly? 

Right now, when I'm using that script, it makes created Bug's priority as empty.

Even when I change to:

if (field == [] || field == null || field == ""){
   issue.setPriorityId(priThree)
}

Yet the logs keep saying the source GenericValue can not be Null 

Alex Koxaras -Relational-
Community Champion
November 17, 2022

@Diana Gorv try the following:

import com.atlassian.jira.config.PriorityManager
import com.atlassian.jira.component.ComponentAccessor

def priorities = ComponentAccessor.getComponent(PriorityManager).priorities;
def defaultPriority = priorities.findByName("Medium");
def priThree = priorities.findByName("Pri 3");
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

if (issue.priority.name == defaultPriority.name || issue.priority.name  == null){
   issue.setPriorityId(priThree.id)
}
Diana
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.
November 17, 2022

It gives back an error "Cannot get property 'name' on null object"

I had also tried telling to get as an Id

if (issue.priority.name == defaultPriority.name || issue.priority.getId().equals(null)){
   issue.setPriorityId(priThree.id)
}

But still get the same error as "Cannot get property 'id' on null object".

Alex Koxaras -Relational-
Community Champion
November 17, 2022

Try issue.priority?.name = null

Diana
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.
November 17, 2022

omg yes it worked! Thank you so much!

I end up deleting issue.priority.name == defaultPriority.name as it turns out, it was not needed.

final script is:

import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.config.PriorityManager
import com.atlassian.jira.component.ComponentAccessor

def field = ComponentAccessor.getComponent(PriorityManager).priorities
def defaultPri = ComponentAccessor.getConstantsManager().getPriorities().find {it.getName().equals("Medium")}.getId()
def priThree = ComponentAccessor.getConstantsManager().getPriorities().find {it.getName().equals("Pri 3")}.getId()

if (issue.priority?.name == null){
   issue.setPriorityId(priThree)
}

Thanks again!!

Suggest an answer

Log in or Sign up to answer