Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with a script to compare dates in Scriptrunner

Aisha M
Contributor
September 26, 2018

I need help with a script to compare dates and return a value of the furthest date. Can someone please help with this. Thank you 

1 answer

1 vote
Nir Haimov
Community Champion
September 26, 2018

If i understand you right, you have 2 customfields of type DATE and you want to compare them and return the furthest date?

For example:

Date A = 01/Nov/2018

Date B = 01/Dec/2018

if B>A return B?

If that is what you want, here the code for this:

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def dateA = customFieldManager.getCustomFieldObject("customfield_11111")
def dateB = customFieldManager.getCustomFieldObject("customfield_22222")

if (issue.getCustomFieldValue(dateA) > issue.getCustomFieldValue(dateB)) {
return issue.getCustomFieldValue(dateA)
} else {
return issue.getCustomFieldValue(dateB)
}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events