How to validate Due date with system date or today's date ??

Arpit Doshi October 2, 2011

Hi,

I am using a Due Date field in my create screen but I am not able to validate it against system date or today's date.
When I use date compare validator and compare Due date with created date it didn't work because while creating a ticket created date is null !!

Thanks !!

3 answers

1 accepted

1 vote
Answer accepted
Dieter
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.
December 9, 2011
In case where all the other weapons fail, i always consider implementing something like that using a groovy workflow validator script. just install the Groovy Script Runner plugin which should also be available for your version. Something like the following in the validator of the create transition should do the job: invalidInputException = issue.getDueDate().after(new Timestamp(System.currentTimeMillis())) ? null: new InvalidInputException("due date must be in future!") I assume you made due date a required field else you would also have to handle the case issue.getDueDate() == null
Dieter
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.
December 9, 2011
Sorry for the bad formatting, aac still doesn't work well with iPad
JamieA
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.
December 9, 2011

Just tested Dieter's solution and it worked fine. I made a couple of minor tweaks:

import com.opensymphony.workflow.InvalidInputException

if (issue.dueDate) {
    if (issue.dueDate.before(Calendar.getInstance().getTime())) {
        invalidInputException = new InvalidInputException("Due date must be in the future.")
    }
}

Like Sanjay Dhandare likes this
Mageswari December 9, 2011

I'm not a technical person; Could you pls. guide me on where to add the mentioned script.

Thanks.

JamieA
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.
December 10, 2011

Not beyond saying read the documentation. If you're not a technical person and don't want to read up on it you probably need another plugin to be honest.

Like Daniel Alonso likes this
Neeta Dubey April 26, 2015

I've have a custom date field "first date". I've modified the script accordingly and placed it at create event however its not validating my first darft date field. It's still accepting past date values. Could you please advice? import com.opensymphony.workflow.InvalidInputException if (issue.First Draft) { if (issue.First Draft.before(Calendar.getInstance().getTime())) { invalidInputException = new InvalidInputException("First date date must be in the future.") } }

Dieter
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.
April 27, 2015

Please replace all occurences of issue.First Draft by cfValues ["First Draft"] Only system fields have getters lije dueDate

Neeta Dubey April 28, 2015

i edited my code however it's still the same. import com.opensymphony.workflow.InvalidInputException if (issue.cf[13919]) { if (issue.cf[13919].before(Calendar.getInstance().getTime())) { invalidInputException = new InvalidInputException("date must be in the future.") } }

Neeta Dubey April 28, 2015

workflow.JPG

Dieter
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.
April 28, 2015

Please look at https://jamieechlin.atlassian.net/wiki/plugins/servlet/mobile#content/view/1212434 howvto correctly use the map cfValues. issue.cf[fieldid] doesn't work cfValues['name of field'] instead shoukd work

JamieA
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.
April 30, 2015

As Dieter said.

1 vote
Ronald Horner December 8, 2011

I would do it in your validator for the Start Progress transition so that your Created date is set. Additionally you won't be able to start progress on a task that has a due date before the created date. This won't require you to use a plugin to get the functionality you are looking for.

However if you want to do it on the Create Issue transition then I would use the JIRA Workflow Enhancer Plugin. Use the Universal Validator on the Create Issue Transition with the following settings:

Expression:

{Due Date} > [now]

Evaluate To:

true

Mageswari December 9, 2011

Thanks, Ronald. Validating an issue in start progress will nor work for me, since we do not want an issue created with a faulty due date. That option gets ruled out;

Workflow enhancer not available for JIRA 4.0.1 used by us.

Also tried the Date compare with Due date and a custom field that populates current system time for comparision - No Use.

0 votes
Mageswari December 8, 2011

Hi,

Have the same problem; Since JIRA accepts past dates in Due date field - would like to validate my due date to be equal to or greater than current date. With Date Compare validator - Says, 'Error creating issue: Could not load validator class'.

Any answers on this would be helpful.

Thanks.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events