It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

groovy syntax for comparing a custom field with a numeric value and returning a text string

Jeannette Lamb Sep 25, 2013

I am trying to compare the custom field Risk_Priority_Value with the number 6 and return the text "High". The value in my JIRA test issue is "27" so Risk_Priority_Value is > 6. Can anyone please help with the proper syntax?


def Risk_Priority_Value=getCustomFieldValue("Risk Priority Value")

if (Risk_Priority_Value).compareTo(6)> 0

return "High"

5 answers

1 accepted

2 votes
Answer accepted
MichałS Sep 25, 2013
import com.atlassian.jira.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField customField_name = customFieldManager.getCustomFieldObjectByName("Risk Priority Value");

if ( issue.getCustomFieldValue(customField_name) > 6) {
return "High"
} return ""

this should work but I have not tested it. Just written from my mind.

Jeannette Lamb Sep 25, 2013

I get this error. did I miss editing a variable?

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script9.groovy: 1: unable to resolve class com.atlassian.jira.ComponentAccessor @ line 1, column 1. import com.atlassian.jira.ComponentAccessor; ^

MichałS Sep 25, 2013

as I mentioned it is written from my mind, quick check in the Java API and it shoud be:

import com.atlassian.jira.component.ComponentAccessor;

0 votes
Henning Tietgens Sep 25, 2013

What kind of custom field is Risk Priority Value? Where do you call the script?

0 votes
JamieA Sep 25, 2013

Impossible to give good advice without answers to Henning's questions - but Michal's answer is valid provided it's a number field.

0 votes
Jeannette Lamb Sep 25, 2013

They are actually 2 scripted fields. Risk Description is the scripted field where I want to display "High". Risk Priority Value is the other scripted field where I am calculating a number based on 3 other fields. see below.

def Risk_Severity = getCustomFieldValue("Risk Severity")

def Risk_Probability = getCustomFieldValue("Risk Probability")

def Risk_Detectability = getCustomFieldValue("Risk Detectability")

if (Risk_Severity) {

return (Risk_Severity * Risk_Probability) * Risk_Detectability


else {

return null


Template: Number Field
Configured searcher: Number Searcher

0 votes
Jeannette Lamb Sep 26, 2013

Thanks, I'll try again. will this still work if I re-configure the 3 fields to be either radio buttons or a select list rather than number fields?

return (Risk_Severity * Risk_Probability) * Risk_Detectability

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in Marketplace Apps & Integrations

Demo Den Ep. 4: Continuous Integration with CircleCI & Jira Software

Get ready! Demo Den Episode 4 is coming your way on Tuesday, May 28, 2018 with a Continuous Integration and Delivery special demo. CircleCI Director of Solutions Engineering, Eddie Webb will show us ...

486 views 0 4
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you