How to compare due date and system time (date) and make other field required?

Serj Shcherbakov August 5, 2015

Hi!

In our case we need to compare two dates in creation stage, and if due date = 2 days or less, make reason field required.

In my imagination with simple script validation is ugly, but seem like this:

if (issue.dueDate) {
    if (issue.dueDate.<=2(Calendar.getInstance().getTime())) {
 cf (1000) is required

Please help me to sort out.
Thanks! 




 

3 answers

1 accepted

2 votes
Answer accepted
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.
August 5, 2015

something like this:

import java.util.concurrent.TimeUnit

def twoDaysFromNow = new Date(new Date().time + TimeUnit.DAYS.toMillis(2))

if (issue.dueDate && issue.dueDate.before(twoDaysFromNow)) {
    return cfValues["Reason"] as boolean
}
Serj Shcherbakov August 5, 2015

Hi Jamie! I test it: If i fill any Due the Reason field is required always. And if i fill in Reason field Jira is continue ask me to fill it again.

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.
August 5, 2015

I didnt' test it and made a typo, I've changed it now

Serj Shcherbakov August 5, 2015

Ok, Jamie thank you! I Checked it again, but problem still actual: "Reason" field is required (always).

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.
August 5, 2015

this is simlpe scripted validator? Add a new line at the end: true

Serj Shcherbakov August 6, 2015

Jamie, yes it is it. Its work now! THANK YOU!

Suresh August 7, 2015

Hi, I am trying following code.please let me know if it wrong. import java.util.concurrent.TimeUnit def today = new Date() if (today == issue.issue.fixVersions*.releaseDate) { return cfValues["RCT Late Approval"] as boolean } Thank you so much in advance....

Serj Shcherbakov August 9, 2015

Hi Suresh, import java.util.concurrent.TimeUnit def today = new Date() if (today == issue.issue.fixVersions*.releaseDate) { return cfValues["RCT Late Approval"] as boolean } true

0 votes
Serj Shcherbakov August 27, 2015

@Jamie Echlin [Adaptavist]

Hi Jamie!

May be you know why script is does not work in production environment, but work fine on test environment.

Addon Version is same.
JIRA version is same.
Fields naming is same.

May be import java.util.concurrent.TimeUnit does not work?

When reason field is filled JIRA still ask me to fill it again.

Please help us!

 

0 votes
Serj Shcherbakov August 10, 2015

Hi Jamie!

May be you know why script is does not work in production environment, but work fine on test environment.

Addon Version is same.
JIRA version is same.
Fields naming is same.

Please help us!

 

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.
August 18, 2015

Did you solve this? There's no reason it shouldn't work afaik.

Suggest an answer

Log in or Sign up to answer