Date Comparion in Universal Condition

James Sorby May 13, 2013

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 votes
Radu Dumitriu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 14, 2013

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

James Sorby May 19, 2013

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.

Radu Dumitriu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 19, 2013

Sure, I can understand that.

0 votes
Timothy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
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;

James Sorby May 19, 2013

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.

James Sorby May 19, 2013

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.

James Sorby May 29, 2013

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.

Suggest an answer

Log in or Sign up to answer