Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Automatically update priority based off of numerical custom field

Adrian_Avalos May 15, 2023

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

0 votes
Adrian_Avalos May 16, 2023

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 Champion
May 15, 2023

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 Champion
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

Adrian_Avalos May 17, 2023

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