Restrict due date using simple script validator

Eric Smith February 25, 2019

I am trying to restrict the due date field by preventing users from setting the due date 24 hours from the date that they are attempting to create the ticket. I am using ScriptRunner to create a simple scripted validator. I have been successful in preventing ticket creation with the below script, but it prevents all tickets from being created (Im guessing it might have something to do with the sql import when im using postgres, but I couldnt find a postgres equivalent).

 

import java.sql.Timestamp
def duedate = issue.DueDate
def noticket = new Timestamp((new Date() +1).getTime())

duedate > noticket

1 answer

1 accepted

0 votes
Answer accepted
Payne
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.
February 25, 2019

issue.DueDate is invalid. Though the compiler doesn't flag it, it gets logged as an error. Try issue.getDueDate() instead.

Note that though the field is of type datetime, the interface accepts only a date, so the system will set the time to 0:00:00, meaning that if the user selects a due date of tomorrow, it will always fail; it will not fail for a due date of 2 or more days out.

e.g. if I create a ticket now with a due date of tomorrow

now = 2019-02-25 14:35

noticket = 2019-02-26 14:35

duedate = 2019-02-26 00:00

duedate > noticket returns false

but if I create a ticket now with a due date of day after tomorrow

now = 2019-02-25 14:35

noticket = 2019-02-26 14:35

duedate = 2019-02-27 00:00

duedate > noticket returns true

Eric Smith February 25, 2019

This worked perfectly! Thank you!

Suggest an answer

Log in or Sign up to answer