Jira Scriptrunner - Set priority to normal if custom field is NOT checked

Anna O. August 22, 2021

Hi dear community, 

I have a very simple request from a user, as it seems to me, but unfortunately with my very very basic coding know-how I cannot do the script. Please help me.

 

This is what my user wants: 

If a certain custom field (namely "production relevant") is NOT checked, the priority should be set to "normal". Else set the priority to "high". 

The custom field id of the production relevant is 12900. 

Thanks in advance!

Best, Anna

1 answer

1 vote
Nic Brough -Adaptavist-
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.
August 22, 2021
Anna O. August 25, 2021

Hi Nic, 

thanks I looked at the script. I am sure, as an expert, you can you some parts of the script. Even though I am not one, just a beginner - in fact - I tried to modify the script but it still brings errors. 

Can you help me further? 

Thanks in advance!


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.PriorityManager
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption

final customFieldName = "Production Relevant"

//Get custom field issue with this name
def customFieldManager = ComponentAccessor.customFieldManager
def customField = customFieldManager.getCustomFieldObjects(issue).findByName(customFieldName)

def customFieldVal = issue.getCustomFieldValue(customField) as LazyLoadedOption

//Create priorities
def priorities = ComponentAccessor.getComponent(PriorityManager).priorities

def highestPriority = priorities.findByName("High")
def normalPriority = priorities.findByName("Normal")

//Assign priority depending on the custom field value
if (customFieldVal?.value == true) {
issue.setPriorityId(highestPriority.id)
}
else {
issue.setPriorityId(normalPriority.id)
}

script.png

Nic Brough -Adaptavist-
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.
August 26, 2021

A post-function script won't work in a Behaviour initialiser, they are for doing totally different things.

Try your script as a post-function, those are for setting field values based on other data.

Like Anna O. likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events