Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Get Last Transition Date using Script Runner

Kevin Seery April 24, 2018

Hi,

I would like to change get the last transition date, how do I change this script runner script to do this?

Many Thanks

Kevin

 

package com.onresolve.jira.groovy.test.scriptfields.scripts

import com.atlassian.jira.component.ComponentAccessor

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def created = changeHistoryManager.getChangeItemsForField(issue, "status").find {
    it.toString == "Done"
}?.getCreated()

def createdTime = created?.getTime()

createdTime ? new Date(createdTime) : null

2 answers

Suggest an answer

Log in or Sign up to answer
0 votes
Mike Quentel February 5, 2024
// can run this example of getting the time in ScriptRunner console
// https://${MY_SERVER}/jira/plugins/servlet/scriptrunner/admin/console

import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
IssueManager issueManager = ComponentAccessor.issueManager
Issue issue = issueManager.getIssueObject("TEST-9999")
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def result = changeHistoryManager.getChangeItemsForField(issue, "status").find {
it.toString == "Done"
}?.getCreated().getTime()

log.debug(result)
0 votes
April June 19, 2018

I'd like to figure this one out to. The problem is this:

I can make a scripted field to capture the date the transition was executed, and I'm all set for new issues.

However, my user just asked to get this populated on existing issues, which means poking through history.

I assume I need to build an array here and look for the last instance, but perhaps there is some more elegant way to do this.

Thanks

TAGS
AUG Leaders

Atlassian Community Events