Date Comparion in Universal Condition

I have a Date Picker field in a form called Start Date. I am trying to create a condition in a workflow that checks that this date is greater or equal to today. I am trying to do this with the Universal Condition of the JIRA Workflow Enhancer plugin but as the Date Picker defaults the time to 00:00:00 a Start Date of today is actually midnight last night. So the boolean equation:

"{Date Due} >= [now]" will actually be False as [now], a default variable in the Universal Condition plugin, includes the time which is obviously greater than 00:00:00.

I have tried to use "{Date Due} >= [now] - 1d" which sounds to me like it should work, but doesn't and always returns False. How can I get a condition which allows for a date picker set to today, regardless of time, to return True when compared to the [now].

Just for information I have also tried things like "[now] - {Date Due} <= 1min", "{Date Due} + 1d >= [now]", "{Date Due} >= [now] - 1d" etc. but nothing seems to work!

If the Universal Condition isn't a possibility, does anyone have any other ideas as to how to achieve this? Remember that I am using a date picker only, NOT a date and time picker (for good reason).

Many thanks.

James.

2 answers

0 vote
Timothy Chin Community Champion May 14, 2013

Not sure of this add-on that you are using but you can use this add-on instead.

https://jamieechlin.atlassian.net/wiki/display/GRV/Script+Runner

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Category

passesCondition = false;
Date date = issue.getCreatedDate();
Date now = new Date();
// Do date comparison

return passesCondition;

Hi Timothy,

Thanks for this. Would be good to try this out. However, i have failed at the first hurdle. I have searched for script runner in the Universal Plugin Manager as the help on your site suggests but I cannot see your plugin appear. What is its actual name? There is one called Jira Scripting Suite. Is it this one?

Many thanks

James.

Hi Timothy,

Thanks for this. I am trying to give it a go. Had this plugin installed already actually, just never really used it so not really sure what I am doing with the programming elements! Anyway, I have tried this script:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Category

passesCondition = true;
Date dateDateDue = $issue.getCustomFieldValue("customfield_10080");
Date dateNow = new Date();

// Do date comparison
#if (dateDateDue < dateNow)
passesCondition = false;
invalidInputException = new InvalidInputException("Date Due cannot be in the passed.")
#end

return passesCondition;

My date field that I am wanting to compare to today is a custom field "Date Picker" with ID 10080. However, this, when saved in a file C:\Program Files\Atlassian\JIRA\atlassian-jira\JavaScriptFiles\ValidateDateDueScript.groovy and referenced in the "Script Validator" file path property of a workflow validator, gives the following error when I try to transition a ticket via this workflow:

"An unknown exception occured executing Validator com.onresolve.jira.groovy.GroovyValidator@4ac5b7: root cause: java.lang.NullPointerException"

What might I be doing wrong?

Many many thanks.

James.

Hi Timothy,

I was wondering if you would have chance to comment on the above? I would really appreciate it. I am sure this is something really simple, but the programming side of Jira is not something I am familiar with.

Many thanks for any help you can offer.

Take care

James.

Or use JJupin https://marketplace.atlassian.com/plugins/com.keplerrominfo.jira.plugins.jjupin if you want to do it easily:

Code should look like:

return startOfDay(customfield_10101) &gt; startOfDay(dueDate); //or whatever

Hi Radu,

Thanks for your response. The plugin that you mention is a costable plugin, and whilst it is not that expensive I was hoping to achieve this without any cost at all. Thanks again.

James.

Sure, I can understand that.

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 Thursday in Jira

Meet the AUG leaders of Northern Virginia

@Rachel Wright (Jira Genie), @Billy Poggi (AUG NOVA, DC), and @Dana Jansen (Confluence Queen) are just some of the folks that lead one of the world's most active Atlassian User Group (AUG)....

125 views 4 9
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