Create a Sub-Task When the Parent Issue Has a Specific Label


Automatically create a sub-task when a specific label is added to the parent issue.


I am working on the help desk and I have been assigned to an issue to check a laptop. I have found that it is broken and needs to be replaced. Therefore, I need to create a sub-task associated with the issue to manage the purchase of the laptop. Using this script, I can label the parent issue with a 'broken' tag so the sub-task is automatically created.

Good to Know

  • Use this script on a script listener triggered for the Issue Updated event.


Jira Jira (7.7 - 8.6)

import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.IssueInputParametersImpl final String newLabel = "create_subtask" def issue = event.issue if (!issue.subTask && newLabel in issue.labels*.label) { createSubtask(issue) } def createSubtask(Issue parentIssue) { def subTaskManager = ComponentAccessor.subTaskManager def asUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser def constantsManager = ComponentAccessor.constantsManager def issueService = ComponentAccessor.issueService def subtaskIssueType = constantsManager.allIssueTypeObjects.findByName("Sub-task") assert subtaskIssueType?.subTask // Fill the required fields def issueInputParameters = new IssueInputParametersImpl() issueInputParameters .setProjectId(parentIssue.projectId) .setIssueTypeId( .setSummary('A new subtask') .setDescription('A description') .setReporterId(asUser.key) def createValidationResult = ComponentAccessor.issueService.validateSubTaskCreate(asUser,, issueInputParameters) if (!createValidationResult.valid) { log.error createValidationResult.errorCollection return } def newIssue = issueService.create(asUser, createValidationResult).issue subTaskManager.createSubTaskIssueLink(parentIssue, newIssue, asUser) }
Discovered an issue? Report it here

Suggested for you