Is there a way to update the Resolved Date for a jira issue?
REST API or any other way?
I have two stories that were done in 2017 but because of the holidays were not closed until the new year. Problem is those two stories are badly distorting some reports and I have been asked to set the resolved dates to a date in the past.
If you have Power Scripts add-on you could write a job with the following script
for (string iKey in selectIssues("your jql query to get issues")) {
%iKey%.resolutionDate = "your date";
}
You can read more about Power Scripts here:
https://confluence.cprime.io/display/TR
If you have ScriptRunner add-on you could write a scirpt with the following method:
MutableIssue.setResolutionDate(Timestamp resolutionDate)
Thank You Alexey,
I do have ScriptRunner, but only used it once while an Atlassian expert was helping to add a script to increment a value in a counter field.
I have probed a bit and think I have built the script I need to update my issue field.
The Timestamp value I want is "12/22/2017 11:11:11:11" and it should be updated on an Issue with a certain Key (EM-412).
Is this script correct to perform the desired action?
===============================================
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.resolution.Resolution
//retrieve a specific issue
IssueManager issueManager = ComponentManager.getInstance().getIssueManager()
MutableIssue myIssue = issueManager.getIssueObject("EM-412")
//update the resolution date
MutableIssue.setResolutionDate("12/22/2017 11:11:11" resolutionDate)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think I missed this line ...
import com.atlassian.jira.ComponentManager
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think your script would look like this
import com.atlassian.jira.component.ComponentAccessor
import java.sql.Timestamp
import com.atlassian.jira.issue.MutableIssue
MutableIssue issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("EM-412")
Timestamp time = new Timestamp(117, 11, 22,11, 11, 11, 0)
issue.setResolutionDate(time);
issue.store()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Console is not liking the issue.store() line because it is deprecated. It says to use the Object's Service or Manager to save values.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
it is a warning, not a error. Just run it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
LOL, As you can see, I am a little skittish because it is so new to me.
But that worked perfectly. Thank you so much for the help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I just stumbled upon your answer, and I have the same problem.
I tried the ScripRunner, but something is wrong, I always get errors like "unable to resolve class import com.atlassian.jira.component.ComponentAccessor".
I'm on Jira Cloud and I know there are some limitations regarding ScriptRunner. Can someone help me out? Have the packages changed? Or is something like that not possible on Jira Cloud?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Needed the same issue, as we had a number of issues without an resolved date.
Here is the script i used to set the resolution date to time then the resolution was first set:
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
import com.atlassian.jira.issue.history.ChangeItemBean
import com.atlassian.jira.issue.changehistory.ChangeHistory
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import org.apache.log4j.Level
import java.text.SimpleDateFormat
import java.sql.Timestamp
import com.atlassian.jira.database.QueryDslAccessor
import com.atlassian.jira.model.querydsl.QIssue
import com.querydsl.core.Tuple
import com.querydsl.core.types.Projections
log.setLevel(Level.DEBUG)
// Get the custom field manager
// Get the QueryDslAccessor
QueryDslAccessor queryDslAccessor = ComponentAccessor.getComponent(QueryDslAccessor.class)
// Define the date format
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
// Get the change history manager
ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
Issues.search('project = LOGS and resolution is not EMPTY and resolved is EMPTY').each{ issue ->
List<ChangeHistory> issueChangeHistories = changeHistoryManager.getChangeHistories(issue)
List<ChangeHistory> resolutionChangeHistories = new ArrayList<>()
for (ChangeHistory changeHistory : issueChangeHistories) {
for (ChangeItemBean changeItem : changeHistory.getChangeItemBeans()) {
if (changeItem.getField().equals("resolution")) {
resolutionChangeHistories.add(changeHistory)
break
}
}
}
if (resolutionChangeHistories.size() > 0) {
ChangeHistory singleResolutionChangeHistory = resolutionChangeHistories.get(0)
Date resolutionSetDate = singleResolutionChangeHistory.getTimePerformed()
Timestamp resolutionSetTimestamp = new Timestamp(resolutionSetDate.getTime())
String formattedResolutionSetDate = dateFormat.format(resolutionSetDate)
log.info(issue.getKey() + ', ' + formattedResolutionSetDate + ',' + resolutionSetTimestamp)
MutableIssue mIssue = Issues.getByKey(issue.getKey()) as MutableIssue
mIssue.setResolutionDate(resolutionSetTimestamp)
// Update the resolution date field using QueryDslAccessor
queryDslAccessor.execute(dbConnection -> {
dbConnection.update(QIssue.ISSUE)
.set(QIssue.ISSUE.resolutiondate, resolutionSetTimestamp)
.where(QIssue.ISSUE.id.eq(issue.getId()))
.execute()
})
issue.reindex()
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@David Harkins was this on Jira Cloud or Datacenter? Based on the DbConnection I'm assuming Datacenter, but just wanted to confirm.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Joe
Generally, you can't do anything with the REST API that you can't do within Jira.
Within Jira, the Resolved Date is a readonly field, so I don't think you can change it in Jira or via the API.
If you have a server version of Jira, you could write some SQL or go directly into the database and change it, but I WOULDN'T RECOMMEND DOING THIS.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.