Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,463,682
Community Members
 
Community Events
176
Community Groups

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

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

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

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

Atlassian Community Events