Sometimes we need to know the “real” closing date of tickets, for different reasons: workflows with bad config (Resolve Issue screen missing in final statuses…), two Resolve Issue screens in Resolved and Closed statuses, etc.

And, as always, we have a trick using the plugin Scriptrunner!

It’s very simple, just create a Scripted custom field and use a configuration like this:

Captura de pantalla 2019-03-26 a las 20.17.10.png

And use and modify this code:


import com.atlassian.jira.component.ComponentAccessor
import java.math.*
import java.util.Date

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()

def done = changeHistoryManager.getChangeItemsForField(issue, "status").reverse().find {
it.toString == "Done"
}?.getCreated()

def closed = changeHistoryManager.getChangeItemsForField(issue, "status").reverse().find {
it.toString == "Closed"
}?.getCreated()

def discarded = changeHistoryManager.getChangeItemsForField(issue, "status").reverse().find {
it.toString == "Discarded"
}?.getCreated()

def doneTime = done?.getTime()
def closedTime = closed?.getTime()
def discardedTime = discarded?.getTime()

def lasttime = null;
if ( closedTime > doneTime && closedTime > discardedTime)
lasttime = closedTime
else if ( doneTime > closedTime && doneTime > discardedTime)
lasttime = doneTime
else if ( discardedTime > closedTime && discardedTime > doneTime)
lasttime = discardedTime

if ( lasttime == null) return null
def date = new Date((long)lasttime);
return date

Remember, the searcher must be “Date Time Range picker

Captura de pantalla 2019-03-26 a las 20.19.29.png

finally place the field on all screens to see this date working!

By MrAddon

Advertisements
Posted by:.

One thought on “Example of script field in Jira to know the Closing date

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s