Forums

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

Update the resolution date on the basis of last status change date

Rituresh Verma December 10, 2021

Hi
I have been asked to update the resolution date of almost 400 tickets with the date the ticket to last transitioned status change date. Filters are not fetching the result, so I am not sure whether it's correct or not?
Is anyone able to suggest the correct way to do this please?

Many Thanks


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.search.SearchQuery
//import com.atlassian.jira.issue.MutableIssue

// Issues returned from that JQL will get altered
final searchQuery = "key in ()"

// Get some components
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issueManager = ComponentAccessor.issueManager
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser

// Perform the JQL search
def query = jqlQueryParser.parseQuery(searchQuery)
def searchResults = searchProvider.search(SearchQuery.create(query, user), PagerFilter.unlimitedFilter)

// Iterate all results
searchResults.results.each { documentIssue ->
def key = documentIssue.document.fields.find { it.name() == "key" }.stringValue()
def issue = issueManager.getIssueObject(key)

//Find the date of last transition to desired status
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def created = changeHistoryManager.getChangeItemsForField(issue, "status").reverse().find {
}?.getCreated()
// The new value to set
final newValue = created

issue.setResolutionDate(newValue)
issue.store()

//ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)

}

 

Regards,
Rituresh Verma

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events