Skip to content

Instantly share code, notes, and snippets.

@jechlin
Created September 12, 2013 20:08
Show Gist options
  • Save jechlin/6543064 to your computer and use it in GitHub Desktop.
Save jechlin/6543064 to your computer and use it in GitHub Desktop.
package examples
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParametersImpl
import org.apache.log4j.Logger
def log = Logger.getLogger("com.onresolve.jira.groovy.MyScript")
def subTaskManager = ComponentAccessor.getSubTaskManager()
def issueService = ComponentAccessor.getIssueService()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def indexManager = ComponentAccessor.getIssueIndexManager()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def Issue issue = issue
def issueInputParameters = new IssueInputParametersImpl()
issueInputParameters.setSummary("some summary")
issueInputParameters.setIssueTypeId(1.toString())
issueInputParameters.setProjectId(issue.projectObject.id)
issueInputParameters.setReporterId(user.name)
def validationResult = issueService.validateCreate(user, issueInputParameters)
assert ! validationResult.errorCollection.hasAnyErrors()
def newParent = issueService.create(user, validationResult).issue
log.debug("new parent created: ${newParent.key}")
// issue = issueManager.getIssueObject(issue.id)
def originalParent = issue.parentObject
log.debug(originalParent)
log.debug(issue.genericValue)
log.debug(newParent.genericValue)
subTaskManager.createSubTaskIssueLink(originalParent, issue, user)
subTaskManager.changeParent(issue, newParent, user)
[issue, originalParent, newParent].each {indexManager.reIndex(it)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment