I have 2 Date custom fields.
Date1 & Date2
Example:
Date1 = 06/12/2023
How to,
when submitting status A to B, there will be a Validator,
the validator :
Date2 field can only select date from a week (7 days, weekend included) counting from the date selected in the Date1 field.
are Date1 and Date2 custom fields of type Date Picker (not Date Time)? And can they be empty or should they both be required?
Hi @David Fischer ,
are Date1 and Date2 custom fields of type Date Picker (not Date Time)? And can they be empty or should they both be required?
>> Date Picker type (not Date Time) and they both is required
Sorry I'm not mention that before..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In that case, you can try this:
!!issue.customfield_12345 && !!issue.customfield_67890 && new CalendarDate(issue.customfield_12345).plusDays(7) <= new CalendarDate(issue.customfield_67890)
where customfield_12345 is Date1 and customfield_67890 is Date2
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @David Fischer ,
I was curious,
if Date1 field type is Date Picker, and Date2 field type is Date Picker (Date Time)
will the query be the same or different?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
it would be different, because you cannot compare Date and CalendarDate objects. So you'd have to convert the Date to a CalendarDate:
!!issue.customfield_12345 && !!issue.customfield_67890 && new CalendarDate(issue.customfield_12345).plusDays(7) <= new Date(issue.customfield_67890).toCalendarDate()
Note that this will convert the date/time value according to the current user's timezone. You can also replace with toCalendarDateUTC() to convert it according to the UTC timezone.
Don't forget to "Accept" the answer if it works for you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @David Fischer ,
"because you cannot compare Date and CalendarDate objects. So you'd have to convert the Date to a CalendarDate"
>> Does this mean I have to change the Date1 field type to Date Time Picker too?
This is the field I am currently using :
Plan CAB Date = Date1 (Date Picker)
Plan Implementation - Date & Time = Date2 (Date Time Picker)
Because, when I tried the query you provided, the validator didn't work.
!!issue.customfield_12345 && !!issue.customfield_67890 && new CalendarDate(issue.customfield_12345).plusDays(7) <= new Date(issue.customfield_67890).toCalendarDate()
Am I missing something?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No you don't need to change your custom fields.
When you say it doesn't work, can you elaborate? Did you try using the "Test Jira Expression" button to test the expression against an issue that has a value for both fields?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
here is the result:
and here is my query:
!!issue.customfield_12553 && !!issue.customfield_12611 && new CalendarDate(issue.customfield_12553).plusDays(7) <= new Date(issue.customfield_12611).toCalendarDate()
issue.customfield_12553 = Date1
issue.customfield_12611 = Date2
And here's an example of a date I tested:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Isn't that what you wanted?
Unless I misunderstood your initial request and what you want is that Date2 is within a week from Date1 (I thought it must be no earlier than a week after Date1). In that case, try this:
!!issue.customfield_12553 && !!issue.customfield_12611 && new CalendarDate(issue.customfield_12553).plusDays(7) >= new Date(issue.customfield_12611).toCalendarDate()
(you might need to replace >= with > depending on how you want to treat Date2 being 7 days after Date1 e.g. Date2=6/21 when Date1=6/14)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
"Unless I misunderstood your initial request and what you want is that Date2 is withing a week from Date1 (I thought it must be no earlier than a week after Date1)"
>> before that, I also want to tell you about this hahahaha :')
I'm so sorry David... sorry for my bad english
and I've tried your query, and it works really well!!
God bless you, @David Fischer
you made my day
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.