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

Script Runner Compare due date to system date for required field

Kevin Dalton Sep 09, 2015

 using a Simple Script Validator and it appears to work but if the due date has past the field I have marked as required wil still be flagged even if it is filled out.

if (issue.dueDate) {

    if (issue.dueDate.compareTo(new Date()) < 0) {

 }

}

6 answers

1 accepted

1 vote
Answer accepted
JamieA Sep 14, 2015

OK, here you go. Change TextFieldA to the name of your custom field, including any spaces or whatever.

 

image2015-9-14 21:11:41.png

0 votes
JamieA Sep 09, 2015

can you post the entirety of your code? Or at least a complete example. 

If that was it, you need:

if (issue.dueDate) {
    return issue.dueDate.after(new Date())
}

or ".before", not sure what you're trying to do.

0 votes
Kevin Dalton Sep 09, 2015

I want a field required if the due date is past.  I have tried what you changed and it works if the due date has not past.  If todays date is the the same as the due date it flags it as required as well as if the due date has past.  If i have the field populated it still throws the errors saying it needs to be populated as well.

JamieA Sep 09, 2015

The due date is a actually a date and time, the time will be midnight on the due date. So if it's the same day, it will actually be after the due date. You can use clearTime() to set your "new Date()" to midnight, and your compareTo should then return equal if it's the same day.

0 votes
Kevin Dalton Sep 10, 2015

Could we do somethiing where we compare the current date to the duedate +1.  This should make it the next day and we would be able to see if it is before or after that.

JamieA Sep 10, 2015

that should also be ok.

Kevin Dalton Sep 10, 2015

Awesome, how would you add 1 day to the duedate

0 votes
Kevin Dalton Sep 14, 2015

So if the due date is past due we want a custom field required but if the due date has not past this field is not required.

0 votes
Kevin Dalton Sep 14, 2015

Thank you.  The team requesting this was very happy.  Another reason why we were happy to purchase Script Runner for all out environments.

JamieA Sep 14, 2015

Thanks for letting me know how it worked out. Can you mark my answer as correct please... it may help others.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Jira

Here’s what we’re doing to make Jira Cloud faster

Hello Community 🤗 I’m Nikhil, a Product Manager on the Jira Cloud team working on performance improvements. Performance is an ongoing journey and we continue to invest heavily in it. We under...

104 views 0 16
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