Groovy-Condition to check date

I want to write a groovy script condition to validate if a date is in the future.

the date is not set in the issue. if the user wants to pass the transition, a pop-up appears with a screen where the (empty) date-field is. he puts in a date and if he submits, the date should be checked.

Problem: println says, cfValues['customfield_13430'] is null. so the whole condition breaks and every time returns the defined error message.

can you help me please?

2 answers

1 accepted

1 vote
Henning Tietgens Community Champion Oct 30, 2013

cfValues takes the name of the field, so try cfValues['My Date'] (or so).

Okay, thank you.

No i can print the correct value (Output: 2013-11-14 00:00:00.0)

But if i compare (as in the screenshot above) i can not pass (but i should, because 2013-11-14 is in the future and i compare to the current date).

Henning Tietgens Community Champion Oct 30, 2013

And take care, because it's the translated name of the custom field. So if you use translated custom fields you should get the cf on your own (using the id or the unrtanslated name) and read the value directly (issue.getCustomFieldValue(cf)) until https://jamieechlin.atlassian.net/browse/GRV-335 is fixed.

0 vote
Henning Tietgens Community Champion Oct 30, 2013

If the custom field is a date field it returns a Timestamp object. This is already a Date object. The getDate() method returns the day of the month (int) not a Date object. So it should be enough to write

cfValues['My Date'] > now

Very good. This works for me:

Date now = new Date()

cfValues['My Date Field'] >= new Date(now.getYear(), now.getMonth(), now.getDate())

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

163 views 0 4
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you