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.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
int dateField1Id = 12500
int dateField2Id = 12501
def 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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
Kris
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What is your requirement ? A condition disables a transition, so you should not even see the button in one case. Maybe add logs and check the logs
if (dateField1Value.compareTo(dateField2Value)){
log.error("condition is true")
passesCondition = true
}
else {
log.error("condition is false")
passesCondition = false
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Antoine Berry ,
I want use "Copy value from field to filed" post function and need to set a condition for it. So, it should only copy value from field to field when the sprint end date bigger than my another date time filed. However, I tried this script but it did copy value all the time. Please help me to fix it. Thank you very much! Btw, I add logs but I don't know how to find it.
Best Regards,
Kris
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Antoine Berry ,
I fixed it and run smoothly now. Really thanks for your help. Could I ask one more question? Do you know how to get epic link's sprint end date by using script? Thank you very much!
Best Regards,
Kris
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Glad you could make it work !
I am not sure about your question : Epics typically run through multiple sprints so they are not linked to one specific sprint. 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.
Hi @Antoine Berry ,
Actually, I am trying to get the sprint from the epic which is in “epic link” field and only need to current sprint of that epic. Could we make it? Thank you very much!
Kris
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well I find it weird that you associate an Epic with a sprint, since epics are typically completed in multiple sprints and are not displayed in the backlog.
But still it is possible using that script :
import com.atlassian.jira.component.ComponentAccessor
int epicLinkId = 10101
def epicLink = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(epicLinkId)
def epicLinkValue = issue.getCustomFieldValue(epicLink)
int sprintFieldId = 10100
def sprintField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(sprintFieldId)
def sprintEndDateValue = issue.getCustomFieldValue(sprintField)?.endDate?.first()?.toDate()
Let me know if that helped.
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.
You are very welcome ! Glad you could make it work. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Antoine Berry ,
Sorry to brother you again, do you know how to write a script to determine which sprint is "active sprint" and which is "future sprint"? Thank you very much!
Kris
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you want to know if the sprint associated with the issue is active, closed or future you can use :
def sprint = issue.getCustomFieldValue(sprintField)[0]
boolean isActive = sprint.isActive()
boolean isClosed = sprint.isClosed()
boolean isFuture = sprint.isFuture()
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.