import com.atlassian.jira.component.ComponentAccessor final String parentIssueKey = "JRA-1" final String issueTypeName = "Sub-task" final String reporterKey = "anuser" final String summary = "Groovy Friday" final String priorityName = "Major" def issueService = ComponentAccessor.issueService def constantsManager = ComponentAccessor.constantsManager def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser def parentIssue = ComponentAccessor.issueManager.getIssueByCurrentKey(parentIssueKey) assert parentIssue : "Could not find parent issue with key $parentIssueKey" def subtaskIssueTypes = constantsManager.allIssueTypeObjects.findAll { it.subTask } def subTaskIssueType = subtaskIssueTypes.findByName(issueTypeName) assert subTaskIssueType : "Could not find subtask issue type with name $issueTypeName. Avaliable subtask issue types are ${subtaskIssueTypes*.name.join(", ")}" def reporter = ComponentAccessor.userManager.getUserByKey(reporterKey) ?: loggedInUser def priority = constantsManager.priorities.findByName(priorityName) ?: constantsManager.defaultPriority def issueInputParameters = issueService.newIssueInputParameters().with { setProjectId(parentIssue.projectObject.id) setIssueTypeId(subTaskIssueType.id) setReporterId(reporter.key) setSummary(summary) setPriorityId(priority.id) } def validationResult = issueService.validateSubTaskCreate(loggedInUser, parentIssue.id, issueInputParameters) assert validationResult.valid : validationResult.errorCollection def issueResult = issueService.create(loggedInUser, validationResult) assert issueResult.valid : issueResult.errorCollection def subtask = issueResult.issue ComponentAccessor.subTaskManager.createSubTaskIssueLink(parentIssue, subtask, loggedInUser)
Overview
Content Tools