Forums

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

setUpdated() not working

Derek Fields _RightStar_
Community Champion
May 30, 2018

I am trying to set the Updated field for an issue via script:

import com.atlassian.jira.component.ComponentAccessor
import java.sql.Timestamp
import java.text.SimpleDateFormat
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue

MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject("SD-1")
def user = ComponentAccessor.getUserManager().getUserByKey("derek.fields")

log.warn "Initial Updated Date is ${issue.getUpdated()}"

String ts = '24-MAY-18 09:07'
String pattern = 'dd-MMM-yy HH:mm'

def sdf = new SimpleDateFormat(pattern)
def ds = sdf.parse(ts)
def timestamp = new Timestamp(ds.getTime())

log.warn "Timestamp is ${timestamp}"

issue.setUpdated(timestamp)
def updatedIssue = ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

log.warn "New Updated value for ${updatedIssue.getKey()} is ${updatedIssue.getUpdated()}"

issue = ComponentAccessor.getIssueManager().getIssueObject(updatedIssue.getKey())

log.warn "Update value in retrieved issue is ${issue.getUpdated()}"

The code should set Updated to be the Timestamp with the 'ts' date in it. I have checked that I am getting a valid timestamp. After I call updateIssue, I am retrieving the issue from the database, but it appears with the old date (that was in the issue when I started)

Here is the log output from my log.warn messages

2018-05-30 16:48:43,981 WARN [runner.ScriptRunnerImpl]: Initial Updated Date is 2018-01-25 11:24:58.554
2018-05-30 16:48:43,984 WARN [runner.ScriptRunnerImpl]: Timestamp is 2018-05-24 09:07:00.0
2018-05-30 16:48:43,984 WARN [runner.ScriptRunnerImpl]: New Updated value for SD-1 is 2018-05-24 09:07:00.0
2018-05-30 16:48:43,985 WARN [runner.ScriptRunnerImpl]: Update value in retrieved issue is 2018-01-25 11:24:58.554

The issue that is returned from the update has the new updated date, but when I go to retrieve it again from the database, it has reverted (or was never changed) to the updated date that I am trying to set 

1 answer

1 accepted

0 votes
Answer accepted
Tuncay Senturk _Snapbytes_
Community Champion
May 30, 2018

As far as I know, it is by design.

You can not change updated field unless you do some hack (modifying the db value).

Derek Fields _RightStar_
Community Champion
May 30, 2018

What is the point of setUpdated () if it doesn't do anything?

Tuncay Senturk _Snapbytes_
Community Champion
May 31, 2018

You're right from this point of view, and you're not alone.

Here you can see similar conversation and a workaround. Thay may help.

Or, could you try adding below statement after updating MutableIssue? (I am not sure, but it may work I guess)

issue.store()
Derek Fields _RightStar_
Community Champion
May 31, 2018

Using issue.store() instead of IssueManager.updateIsssue worked - which is frustrating. It is also risky as a long-term solution, since store() is deprecated. The good news is that I should only have to use it for a short term fix. 

I also determined that it is possible to do a direct database update into the jiraissue table, so that it a less risky workaround since that table structure is stable.

Thanks for the help

Tuncay Senturk _Snapbytes_
Community Champion
May 31, 2018

Glad to hear that

Suggest an answer

Log in or Sign up to answer