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

How to use greater than / less than operators in Scriptrunner condition

Gavin Minnis December 18, 2018

I have two custom Text Field - (Single Line) fields in my project. Each field contains a number.

I am using a Scriptrunner Fast-Track Post Function to transition my workflow when Field Value 1 is larger than or equal to Field Value 2. However, when I cannot determine how to set the Condition of the Fast-Track Post Function to accomplish this.

For example, right now I am trying:

cfValues['Custom Field 1'] >= cfValues['Custom Field 2'] 

 The script above results in the following message:

Cannot find matching method java.lang.Object#compareTo(T).

When I ignore the static type checking message, I can get the Fast-Track to work. But it is not working correctly--based on the logic in the script above. Does anyone have another way to approach this?

2 answers

1 accepted

0 votes
Answer accepted
Nic Brough -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.
December 19, 2018

The comparisons will only work when the objects in the field support it.  I know you've got numbers in your fields, but the fields are still string based, so they could be trying to do things like 'is "flibble" > "lister"?', which is obviously not a valid comparison. 

The comparators basically only work with numeric-like fields.  In your data, while you may have "1, 2, 3, 4, etc", you actually have those numbers as their names.  It might be easier to imagine the data actually contains "one, two, three, four, etc", which obviously can't be compared logically by computers.

So, either swap the fields to numeric types that can support comparators, or try to parse the custom field values into numbers before the comparison.

Gavin Minnis December 19, 2018

Thanks, Nic. As you said, the field type was the issue. I got the fast-track working correctly now.

Tom February 4, 2020

FYI i have two number fields and am getting the same error.

cfValues['Hours Spent'] > cfValues['Estimated Hours']

0 votes
Gavin Minnis December 19, 2018

I found the following on the Atlassian support site:

GREATER THAN: >

The ">" operator is used to search for issues where the value of the specified field is greater than the specified value.

Note that the ">" operator can only be used with fields that support ordering (e.g. date fields and version fields), and cannot be used with text fields. To see a field's supported operators, check the individual field reference.

I am currently working with text fields and I am curious to know if that is the problem. I am going to switch to number fields to see if this corrects the problem, and I will report back.

Jane Brooks March 26, 2019

Gavin, I'm interested in your result when you switched these to number fields. I am about to build a similar function (if value is greater than X, set the value of another field to Y) and I'd love to know before I build it if number fields worked. (They didn't the last time I tried this, but I know that post function had other problems preventing it from working - it was a bad UI anyway.)

Let me know what your results were. Thanks!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events