Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to restrict Priority regarding issue type

Bonjour, 

In Project PROJ1, there are

- priority scheme listed as Low, Medium, High

- issue type scheme request and bug

 

I would to create a Behavior to restrict the available list of Prorities regarding issue type

Request would be proposed Low, Medium 

Bug would be proposed Medium and High

How could I achieve this° 

Regards, 

Guillaume

 

1 answer

Bonjour @Guillaume MACKOWIAK If this is system Priority field you have to apply Script Runner Behaviour on "Issue Type" and add the following Server Side Script :- 

 

import com.atlassian.jira.component.ComponentAccessor

import static com.atlassian.jira.issue.IssueFieldConstants.PRIORITY

def constantsManager = ComponentAccessor.getConstantsManager()
def formField = getFieldById(PRIORITY)

if (issueContext.issueType.name == "Bug") {
def optionsMap = ComponentAccessor.getConstantsManager().getPriorities().findAll { priority ->
priority.getName() in ["Major", "Minor"]
}.collectEntries {
[(it.id): it.name]
}
formField.setFieldOptions(optionsMap)
} else {
def optionsMap = ComponentAccessor.getConstantsManager().getPriorities().findAll { priority ->
priority.getName() in ["Minor", "Trivial"]
}.collectEntries {
[(it.id): it.name]
}
formField.setFieldOptions(optionsMap)
}

 https://scriptrunner.adaptavist.com/4.3.2/jira/recipes/behaviours/restricting-priority-and-resolution.html

Thank you very much ! It worked fine for me.

However, is it possible to change the current priority when I change the issue type in the issue creation screen ?

I would like to prevent a restricted priority to be set to an issue by changing its type after settings the priority.

For example something like this :

when issueType changes
  if (issueType == Bug)
    priority = "high"
  else
    priority = "medium" // because other issue types don't have the high priority

I tried this :

import com.atlassian.jira.component.ComponentAccessor
import static com.atlassian.jira.issue.IssueFieldConstants.PRIORITY

def formField = getFieldById(PRIORITY)

if (getActionName() in ["Create Issue","Create"]) {
if (issueContext.issueType.name == "Bug") {
formField.setFormValue("High")
} else {
formField.setFormValue("Medium")
}
}

but then I can't change the priority anymore as it resets it all the time to the default value.

How can I execute the script only when the issue type is changed ? 

Hi @sChupin Try below script :- 

Except Bug issue type, value come back to "Major".

Kindly apply Behaviour on Issue Type field.

import com.atlassian.jira.component.ComponentAccessor

import static com.atlassian.jira.issue.IssueFieldConstants.PRIORITY

def constantsManager = ComponentAccessor.getConstantsManager()
def formField = getFieldById(PRIORITY)

if (issueContext.issueType.name == "Bug") {
formField.setFormValue("Blocker")
formField.setReadOnly(true)
} else {
formField.setFormValue("Major")// set value as per your requirement
formField.setReadOnly(true) //make field read only
}

 Thanks

V.Y

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

Send an Email or Publish to Confluence - What should you do with your release notes?

Background When you hear the words ‘Release notes’, almost always you think of an unsolicited email from a software vendor. But I am here to tell you that from our data, sending release notes via E...

126 views 1 2
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you