How to set Priority field required using behaviour

Tal Kdoshim November 15, 2023

Hi, 

I'd like to set priority field mandatory upon creation of a ticket, in specific projects, for bug issue type.

after defining the relevant mapping (specific projects + bug issue type) I tried several scripts that didn't work. 

 

can you advise?

3 answers

2 accepted

1 vote
Answer accepted
Tal Kdoshim November 15, 2023

I was able to solve issue by writing a server side script:

import com.atlassian.jira.issue.priority.Priority
import com.atlassian.jira.component.ComponentAccessor

def priorityField = getFieldById("priority")
def action = getAction().toString()
log.debug("Action - '${action}'")

if (((Priority) priorityField.value).name in ["Not-Set"]) {
log.debug("Priority field was not filled in")
priorityField.setError("Priority field is required for bugs")

}else{
// If a valid value is entered clear any errors and accept the value
priorityField.clearError()
}

0 votes
Answer accepted
Tal Kdoshim November 15, 2023

Thanks @Craig Nodwell , I tried the following - 

import com.atlassian.jira.issue.priority.Priority

def priorityField = getFieldById("priority")

priorityField.setRequired(true)

-----------------

I do see the red asterisk next to Priority field, but it's not behaving as a required field

Craig Nodwell
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 15, 2023

I'm sure that your priority field has a default value, so it's going to evaluate to true as a required field.  If you want to test for change on the default value to ensure that an entry has been made then the above will have to be changed up to test for that change.  Or perhaps instead of a behaviour, you could use a script as a post function on the create transition to ensure that a change to that field happened. 

I'll try and send you an example later today, my lunch is over :( 

Tal Kdoshim November 15, 2023

@Craig Nodwell this is indeed the issue, thanks.

It seems that Priority field must have a default value, I need to find a solution that would check if the priority is still 'Not-Set' (default value) - place an error message, asking users to modify it.

I do need to be a behaviour and not a post function, because I have dozens of projects I would need to define it in.

If you have an idea what script I should to achieve the above I will be grateful. 

Thanks for your help

0 votes
Craig Nodwell
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 15, 2023

Hi @Tal Kdoshim there's a great example here

You could easily modify this to suite your needs.

Suggest an answer

Log in or Sign up to answer