For eg -
When status is moved from open to In progress,should get the first date when its moved to In progress using a Scripted field
Try this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.changehistory.ChangeHistory
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
import java.sql.Timestamp
ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
String fieldName = "Status"
String statusName = "In Progress"
Issue issue = issue as Issue
List<ChangeHistory> allChanges = changeHistoryManager.getChangeHistories(issue)
List<ChangeHistory> cfChanges = []
Timestamp firstChange = null
allChanges.each { ChangeHistory change ->
if (fieldName.toLowerCase() == change.getChangeItemBeans().field[0].toLowerCase()) {
cfChanges.add(change)
}
}
if (cfChanges) {
// Additional sorting by date
cfChanges = cfChanges.sort {
it.getTimePerformed()
}
firstChange = cfChanges.findAll {
it.getChangeItemBeans().toString.first() == statusName
}.first().timePerformed
}
return firstChange
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.