setCreated() method throwing a static error while setting up the created date

Vineela Durbha
Contributor
May 21, 2019

I am trying to set created to current date using below method in my script,but it is throwing error "cannot find matching method com.atlassian.jira.issue.MutableIssue#setCreated(long)"

newIssue.setCreated(System.currentTimeMillis())

 Any one can help me on what is wrong here

2 answers

2 accepted

0 votes
Answer accepted
Marcos Sanchez
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.
May 23, 2019

Hi,

That's because the setCreated() method needs a TimeStamp to set the new created date.

If you want to set created date to "currentTimeInMillis" you could try with something like this:

import com.atlassian.jira.component.ComponentAccessor
import java.text.SimpleDateFormat
import java.sql.Timestamp
import java.util.Date

def issueManager = ComponentAccessor.issueManager
def customFieldManager = ComponentAccessor.customFieldManager

def createdDate = new Date(System.currentTimeMillis())

def df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH);
def dt = df.format(createdDate)
def date = df.parse(dt)
def ts = new Timestamp(date.getTime())

//note that "issue" is the issue you want to set the created date.
//In your case may be newIssue as I can see in the code you've pasted.

issue.setCreated(ts)
issue.store()

 

Best Regards,

Marcos

Vineela Durbha
Contributor
May 23, 2019

Thanks for the answer..it worked

Like Marcos Sanchez likes this
0 votes
Answer accepted
Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 22, 2019

Hi @Vineela Durbha ,

Looking at the error message and at the api, setCreated method is expecting a timestamp object, try

import java.sql.Timestamp

newIssue.setCreated(new Timestamp(System.currentTimeMillis()))

instead.

Antoine

Vineela Durbha
Contributor
May 23, 2019

Settling to timestamp worked

Like Antoine Berry likes this

Suggest an answer

Log in or Sign up to answer