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

Scriptrunner Behavior: Set field description based on combination of field values

Ashley Honeycutt October 31, 2024

I've done this before with the behavior set based on a single custom field value, but for some reason this isn't working for the combination of field values. 

The scenario is that we have an Impact field and an Urgency field. If the highest value in both fields is selected, I want text to display to verify if they are sure about that selection.

Here's what I've tried:

 

def cf1 = getFieldByName('Impact')
def cf2 = getFieldByName("Urgency")

def cf1Value = cf1.getValue() as String
def cf2Value = cf2.getValue() as String

if(cf1Value == "Critical" && cf2Value == "High"){
    cf2.setDescription("warning text")
}

if(cf1Value !="Critical Business/Ops Impact"){
    cf2.setDescription("normal description")
}

I've tried adding this to both fields and the behavior does not work on either.


Any suggestions are greatly appreciated!

2 answers

0 votes
Evgenii
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 31, 2024

Hi, @Ashley Honeycutt 

For your scenario you must add "Urgency" field in behaviour and add script there. Also you must look at changed field. It will do the trick. Every time, when "Urgency" field will change, behavior will trigger again
Try this solution:

 

import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

FormField cf1 = getFieldByName('Impact')
FormField cf2 = cfoField = getFieldById(getFieldChanged())

String cf1Value = cf1.getValue() as String
String cf2Value = cf2.getValue() as String

if(cf1Value == "Critical" && cf2Value == "High"){
cf2.setDescription("warning text")
}

if(cf1Value !="Critical Business/Ops Impact"){
cf2.setDescription("normal description")
}
0 votes
Radek Dostál
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.
October 31, 2024

You would indeed need to add that script for both fields, so that it can trigger whenever each of the field is being updated.

 

You should add some logging to see what values are you getting from FormField#getValue() though because that is probably the reason.

 

Add this after your getters

log.warn("cf1Value=" + cf1Value)
log.warn("cf2Value=" + cf2Value)

 

Get the behaviour to run, and then check what you see in the logs if the values are being read as you'd expect.

 

 

Suggest an answer

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

Atlassian Community Events