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