Script Runner Version 6.56.0
Jira Version 8.22.6
I am new to script runner and scripting. Can someone give me an example of how to get the date values of 2 fields and compare the dates and throw an error if the requested date is less than the delivery date.
Hi,
I think this script is a good starting point
https://library.adaptavist.com/entity/calculate-the-difference-between-two-dates
when you get the date value you check both of them like this
if(date1 > date2){
instruction code
}
Yes I have that working but the problem that I am having:
def cf1 = getFieldByName(First Date Field)
def cf2 = getFieldByName(2nd Date Field)
def cf1Value = cf1.getValue()
def cf2Value = cf2.getValue()
Date DateValue1 = Date.parse('dd/MMM/yy h:m', cf1)
Date DateValue 2 = Date.parse(('dd/MMM/yy h:m', cf2)
if(DateValue1.getTime() < DateValue2.getTime())
{
cf1.setError(Error msg)
}else{
cf1.clearError{}
}
This script works but I am getting the error "groovy Exception, cannot cast object with class 'java.lang.string to class 'java utl.date
So I tried converting my string to a date
However it is not working.
Also in the log when I print out the date field the date format is different than when when I print out the field value....?log.debug - cf1 field is :form field ID: customfile_xxxxx,, value: 24/Jan/23
when I print out the getvalue I get th following
log.debug. The Value of cf1 is Tue Jan 24 13:37:00MST 2023
Why are the date formats different between getting the value of the field and printing out the field?
Why is my date conversion not working?
In jira the date displays as 24/Jan/23
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.