Skip to main content
Example scripts
arrow icon
To homepage
Jira
Data centre icon
Data Center

Create a Backdated Issue

Created 1 year ago, Updated 1 day(s) ago
App in script
ScriptRunner For Jira
ScriptRunner For Jira
by Adaptavist
Compatibility
compatibility bullet
Jira (8.0 - 8.14)
compatibility bullet
ScriptRunner For Jira (6.18.0)
Language |
groovy
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

import java.sql.Timestamp
import java.time.LocalDateTime

def PROJECT_KEY = "TEST"
def YEAR = 2012
def MONTH = 12
def DAY = 21
def HOUR = 18 //This is server time (TimeZone)
def MINUTE = 6
def SECOND = 6

def SUMMARY = "The issue summary"
def DESCRIPTION = "The issue description"

def project = ComponentAccessor.projectManager.getProjectObjByKey(PROJECT_KEY)
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

Timestamp timestamp = Timestamp.valueOf(LocalDateTime.of(YEAR, MONTH, DAY, HOUR, MINUTE, SECOND))

if (project && timestamp) {
    MutableIssue issue = ComponentAccessor.issueFactory.issue
    issue.projectObject = project
    issue.summary = SUMMARY
    issue.created = timestamp
    issue.issueType = project.issueTypes.first()
    issue.description = DESCRIPTION
    ComponentAccessor.issueManager.createIssueObject(loggedInUser, issue)
}
Having an issue with this script?
Report it here