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.
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.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try issue.priority?.name = null
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!!
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.