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,554,391
Community Members
 
Community Events
184
Community Groups

Automatically update priority based off of numerical custom field

Hello. I'm looking to build out something that would automatically update priority of issue dependent on value of numerical custom field I have created in Scriptrunner (Numerical Custom Field C). I think has to be built out via Scriptrunner Behaviour, but am not sure on how to write script as I'm very new to scriptrunner. Any help would be greatly appreciated.

 

For background, I have a numerical custom field I created via scriptrunner (Custom field C) which is the result of two numerical custom fields being multiplied (Numerical Custom Field A and Numerical Custom Field B) 

2 answers

Modified to the below, but doesn't appear to work. 

 

import static com.atlassian.jira.issue.IssueFieldConstants.PRIORITY
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours
def rating = getFieldById(fieldChanged)
def ratingValue = rating.value as Long

def priority = getFieldById(PRIORITY)


if (ratingValue >= 13) {
 priority.setFormValue(10000) // critical
} else if (ratingValue >= 9 && ratingValue < 12) {
 priority.setFormValue(2) // high
} else if (ratingValue >= 4 && ratingValue < 8) {
 priority.setFormValue(3) // medium
} else if (ratingValue >= 1 && ratingValue < 3) {
 priority.setFormValue(4) // low
}

 

Also to note, my custom field Rating does not appear on create screen, despite being in scope, being added to field configuration, and being added to field screen

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 15, 2023 • edited

Hi @Adrian_Avalos 

For your requirement, you must create a Server-Side Behaviour for the custom number field.

Below is a working sample code for your reference:-

import static com.atlassian.jira.issue.IssueFieldConstants.PRIORITY
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours
def sampleNumber = getFieldById(fieldChanged)
def sampleNumberValue = sampleNumber.value as Long

def priority = getFieldById(PRIORITY)


if (sampleNumberValue >= 10) {
priority.setFormValue(1) // highest
} else if (sampleNumberValue >= 8 && sampleNumberValue < 10) {
priority.setFormValue(2) // high
} else if (sampleNumberValue >= 6 && sampleNumberValue < 8) {
priority.setFormValue(3) // medium
} else if (sampleNumberValue >= 4 && sampleNumberValue < 6) {
priority.setFormValue(4) // low
} else if (sampleNumberValue >= 2 && sampleNumberValue < 4) {
priority.setFormValue(5) // lowest
}

Please note that the working sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a screenshot of the Behaviour configuration:-

behaviour_config.png

Below are a couple of test screenshots for your reference:-

test1.pngtest2.png

test3.pngtest4.png

test5.pngtest6.png

If you observe the screenshot displayed above, you will notice as the number field is updated, the priority field is updated accordingly.

 

I hope this helps to answer your question. :-)

Thank you and Kind regards,

Ram 

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 16, 2023

Hi @Adrian_Avalos

Could you please share a screenshot of your Behaviour configuration?

In your last comment, you mentioned:-

Also to note, my custom field Rating does not appear on create screen, despite being in scope, being added to field configuration, and being added to field screen

Please clarify, on which screen have you added your Rating field? Is it on a Transition screen, or is it not visible, although you have added it to your Create screen?

Kindly share the screenshots of your screen configuration so I can get a clearer picture and provide you with a better solution.

Also, please reply to this message thread.

Thank you and Kind regards,

Ram

Hi @Ram Kumar Aravindakshan _Adaptavist_ here is screenshot of behaviour.

And Rating custom field is on Create, Edit, and View Screen, however it's not visible on Create screenRating Behaviour.PNGRating Custom Field.PNG

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events