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

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

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

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

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.

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

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

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

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.

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
Community showcase
Published in Jira Service Desk

The Complete Guide to Atlassian for ITSM

Hi Atlassian Community! This is Teresa from the Atlassian team. My colleague Paul Buffington @Buff and I are excited to share a brand new ITSM resource we’ve created – "The Complete Guide to At...

2,186 views 15 22
Read article

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