Hi all,As title, I don't know how to write condition which can compare two different date. Can someone provide a simple script for me? Thank you very much!
Best Regards,
Hi @Kris Han ,
With this script you can compare two date fields in a condition :
import com.atlassian.jira.component.ComponentAccessordef customFieldManager = ComponentAccessor.getCustomFieldManager()int dateField1Id = 12500int dateField2Id = 12501def dateField1 = customFieldManager.getCustomFieldObject(dateField1Id)def dateField2 = customFieldManager.getCustomFieldObject(dateField2Id)def dateField1Value = issue.getCustomFieldValue(dateField1)def dateField2Value = issue.getCustomFieldValue(dateField2)if (dateField1Value.compareTo(dateField2Value)){passesCondition = true}else {passesCondition = false}
Hope that helps.
Antoine
Hi @Antoine Berry ,Thank you very much! One more quick question, how do I check the datefieldID? Can I use xpath instead of field Id? Thank you very much again.
Kris
The best practice is to use the id so the script will keep working even if you change the name. You can find the id in the url when you are on the edit page of the custom field.
Hi @Antoine Berry ,
Sorry to brother you again, I tried the script but it did not work. I used it on the copy value of post-function and it always did copy value action either the date filed 1 bigger than date filed 2 or date field 2 bigger than date filed 1. Could you help me to figure it out? Thank you very much!
It looks like you're new here. Sign in or register to get started.