Setting issue created date with scriptrunner

anorakgirl September 6, 2017

I am trying to change created date for an old issue using the Adaptavist scriptrunner console. I have been abnle to change summary but changes to date created don't seem to save. This is my script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import java.util.Calendar
import com.atlassian.jira.event.type.EventDispatchOption

MutableIssue issue = ComponentAccessor.getIssueManager().getIssueByKeyIgnoreCase('ABC-12')

Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(TimeZone.getTimeZone("Europe/London"))
calendar.set(Calendar.MONTH, 7);
calendar.set(Calendar.DAY_OF_MONTH, 10);

issue.setCreated(new java.sql.Timestamp(calendar.getTimeInMillis()))
ComponentAccessor.getIssueManager().updateIssue(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), issue,EventDispatchOption.ISSUE_UPDATED, false)

Should this be possible or ir there another way to do it?

Thanks!

 

2 answers

1 vote
Tayyab Bashir
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.
September 6, 2017

Hi, 

I don't this is going to work. I've tried it but it doesn't work that way. 

As an alternate approach you can alter the value in database.
That would work fine. But why would you need to change the created date anyway.
You would need to be cautious about it. 

anorakgirl September 6, 2017

Thanks for the reply. I can understand why it wouldn't work :(

I want to send an export of some issues to a customer, and forgot  to enter an issue until today even though it was fixed ages ago. It would look much neater to the customer if the created date was correct.

Tayyab Bashir
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.
September 6, 2017

Well in that case if it is just one single issue. 
you can find that issue in database and update its created date.
You can use the following queires:

To get the issue (we need id from here)

Select id, created 
from jiraissue
where project = 1234 and issuenum = 123;

Issuenum is the actual number of the issue, for e.g. the issue key is Test_Proj-123, then the issuenum is 123.
Project is the projectid. (get it from the admin -> detail) at the end of url. 

Assume we get id = 10101

Then update the issue

update jiraissue 
set CREATED = '2017-09-04 16:17:49'
where id = 10101

 That wil update the created date of said issue to sept 4th and to the according time.

 

Hope this helps.

Like Taylor Chase likes this
0 votes
Maitrey Patel September 15, 2017

Why don't you simply try project import wizard? This has an ability to update multiple issues' created datetime in one go without any problem.

For that, you can create a CSV file including details like key, created and summary.

key created summary
SR-545520/02/17 00:00test 1
SR-567117/03/17 00:00test2 
SR-56725/4/2017 0:00test 3
SR-56731/3/2017 0:00test 4
SR-56749/3/2017 0:00test 5

Just make sure that key and summary are as per the issue.

Cheers,
Maitrey

 

Suggest an answer

Log in or Sign up to answer