How to change the last updated or the last modified date on a JIRA ticket?

Sri Vulli February 4, 2018

Is it possible to do that without making the changes on the DB directly? I tried to import CSV method. That works only on date created but not on date modified. I believe the import is changing the date as I list in the CSV and then updating the last updated time to current date and time since the update was made.

 

2 answers

1 accepted

0 votes
Answer accepted
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 4, 2018

If you have Scriptrunner or something that let you write scripts using Jira Java Api, you can try using MutableIssue.setUpdated(Timestamp) function. then you have to store the value using MutableIssue.store()

Sri Vulli February 5, 2018

Thanks. I will have to learn how to do this.

Do you know if there are any sample scripts somewhere?

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 6, 2018

If you create a post function. I think your script will look like this

java.util.Date now = calendar.getTime();

java.sql.Timestamp currentTimestamp = new java.sql.Timestamp(now.getTime())

issue.setUpdated(currentTimestamp)

issue.store()

I did not try the code. There can be typos.

Sri Vulli February 7, 2018

This worked. Thanks a lot

3 votes
Loïc Dewerchin May 28, 2019

Hello,

 

the accepted solution uses the issue.store() method , which is deprecated:

store() Deprecated.  Use the Object's Service or Manager to save values. Since v5.0. DO NOT USE THIS as it overwrites all the fields of the issue which can result in difficult to reproduce bugs Prefer to use QueryDslAccessor to change only needed fields

 

There are three ways to update an issue : listed in this excellent article : https://community.atlassian.com/t5/Agile-articles/Three-ways-to-update-an-issue-in-Jira-Java-Api/ba-p/736585

I tried them out :

* IssueManager : use the setUpdated() with a Timestamp on the Issue object , then  use the updateIssue() method of the IssueManager.  This does not work, the Updated field will always be overwritten with the current date.

* CustomField:  the Updated field is not a customfield, so that does not work.

* IssueService: the IssueInputParameters class does not have a method to set the Updated field.

 

So I did not find a way to safely update the Updated field of an issue. Like the deprecation notice suggest, your best bet seems the QueryDslAccessor and write in the DB directly.

 

Now, as an extra : I will add my use case in the hope it can help somebody in the future. I was searching for a way to update an issue without changing the "updated" field, which led me to this issue (did not find anything else).   

This is possible by using the second method, with CustomField.

Something like this :

yourCustomField.updateValue(null,issue,new ModifiedValue("",newValue),new DefaultIssueChangeHolder())

Using this method is different then the rest, the action not registered as an update : the Update field does not change , you don't have to specify an ApplicationUser to link the action to, there is no update in the history tab.

 

hope this helps someone.

Leirbag Assuab October 23, 2019

Hi @Loïc Dewerchin ,

Thanks for this useful info.

I've also been looking for a couple of days for a way to just update "modified date" of an issue, without success. It seems the only way is writing in the DB directly.

Now, I'm facing a new scenario where I need to set value for a new CF in all existing issues. Responsible of the project doesn't want all updated dates set to "now". I think this is a common scenario. Atlassian should give us an easy way to achieve this even if it was scripted method.

Last thing, a full sample code of your method can be found here: https://community.atlassian.com/t5/Answers-Developer-Questions/Set-JIRA-Service-Desk-Custom-Field-in-groovy/qaq-p/518940.
Hope it can help someone else.

Like # people like this

Suggest an answer

Log in or Sign up to answer