This article was written by Marko Blagus, our consultant hero.
Managing complex tasks in Jira often requires breaking them down into smaller, manageable pieces. Jira Subtasks allow you to divide larger tasks into detailed subtasks, helping teams track progress more effectively and ensure nothing goes unnoticed.
However, manually creating subtasks can be time-consuming. This guide demonstrates how to automate subtask creation on Jira Cloud, streamlining your workflow and boosting efficiency while maintaining great task organization.
About Jira subtasks
If you’re looking to learn more about Jira subtasks – what they are, how to create them manually, manage them effectively, and follow best practices – be sure to check out our complete guide to Jira subtasks.
How to automatically create subtasks in Jira
The most common method for automating subtask creation is through Automation for Jira, which will be the primary focus of this blog post. However, other approaches include using third-party marketplace apps like ScriptRunner or leveraging Jira Cloud REST APIs in external scripts.
Automation for Jira
If you’re new to automation rules in Jira, there’s no need to worry – we’ve got you covered! Check out our Jira automation basics guide to learn essential concepts and gain practical knowledge to get started.
Trigger
To set up a simple automation rule for creating subtasks, start by configuring a trigger – an action that activates your automation. In this example, we’ll create subtasks automatically when you begin working on an issue and identify additional tasks that need to be completed.
Here are some other potential triggers that can be helpful for automatically creating subtasks:
- Issue created: Automatically create subtasks when a parent issue is created.
- Issue assigned: Assign all subtasks to the same assignee as the parent issue.
- Issue linked: Create subtasks for the source or destination issue when an issue is linked.
- Field value changed: Trigger subtask creation when a specific field related to subtasks is updated.
You can use any trigger offered by Jira automation, just make sure to pick the one that’s best for your needs.
Conditional Logic
After you’ve configured your trigger, the next optional step is to add a condition. Not all automation rules require a condition, but in this example, we will use condition that checks if the issue that triggered the automation rule has issue type Task.
This is a simple condition but you can also use some other conditions in your automation:
- Issue Fields Condition: Check if some specific field has some specific value required for subtasks creation.
- IF or ELSE: To expand the first condition for example (Issue Fields Condition), you can add IF/ELSE to check for more specific field values and create subtasks accordingly.
- JQL condition: If issue matches given JQL query, subtasks will be created.
Make sure to pick the right condition since this will decide for which issues the automation rule will be executed.
Action
This is the part that will do the actual work for you. Jira has a Create sub-tasks action built-in, which we will use in this example.
After you added this action:
You will see this in action details:
You can just add a summary for subtasks that need to be created and you can click Add another sub-task to create more subtasks at once.
If you want to create subtasks with only summaries, you need to know if there are some required custom fields that may block issue creation.
To edit more fields when creating subtasks, you can click the Add fields button, which will provide you with a more detailed issue creation screen.
This screen will open and you will be able to add some values manually or you can copy field values from the parent or epic issues.
You will be able to add some values manually or you can copy field values from the parent or epic issues. By clicking on 3 dots, and choosing COPY over SET value, you can copy value from the same field or different fields from parent issue.
In this example we will copy Description value from issue to its subtask:
Field value can also be copied by using the following options:
- Trigger issue: Since the issue triggering automation rule is parent.
- Parent issue: Same explanation as for trigger issue.
- Epic issue: If you want to copy from epic.
Instead of using the current issue as shown in the given example.
A simple automation rule for creating subtasks for an issue in progress would look something like this:
Another possible way of creating new subtasks with automations is by using Create issue instead of Create sub-tasks action.
After you open it, you need to choose Sub-task for issue type and also, pick Current issue or Trigger issue as Parent issue.
Both ways are almost the same and both can be used to create subtasks in automation rules.
These are simple but effective ways to automate subtasks creation in automation rules. You can always make automation more custom and add more elements but this can serve you as a good starting point.
This image shows Task before automation rule is executed:
After you transition issue and automation rule is executed, subtask should be created and visible when you open your Task issue:
ScriptRunner for Jira
As mentioned previously in this guide, subtasks creation can also be automated by using a third-party application called ScriptRunner for Jira.
It has some powerful features that can be implemented for effective Jira subtasks creation and it’s great because it allows you to customize your automation even more.
Script Listeners
Script Listeners serve as listeners to Jira events and then run a configured script. They can be very useful in automation because they can listen to events such as:
- Issue created
- Issue updated
- Issuelink created
- Sprint created
ScriptRunner already has an example script for creating subtasks when an issue is created:
//If issue is a subtask, script is not executed
def fields = issue.fields as Map
def issuetype = fields.issuetype as Map
if (issuetype.subtask) {
return
}
// New created issue
def issueKey = issue.key
// Get the issue
def issueResp = get(“/rest/api/2/issue/${issueKey}”).asObject(Map)
assert issueResp.status == 200
def issue = issueResp.body as Map
// Get the issue types for the instance
def typeResp = get(‘/rest/api/2/issuetype’).asObject(List)
assert typeResp.status == 200
def issueTypes = typeResp.body as List<Map>
def listOfsummaries = [‘Subtask summary 1’, ‘Subtask summary 2’] // The summaries to use for
def subtaskIssueType = ‘Sub-task’ // The Sub Task Issue Type to Use
// Get the sub task issue type to use
def issueTypeId = issueTypes.find { it.subtask && it.name == subtaskIssueType && !it.scope }?.id
assert issueTypeId: “No subtasks issue type found called ‘${subtaskIssueType}'”
// Get the project to create the subtask in
def project = fields.project
listOfsummaries.forEach { summary ->
// Create the subtask
def resp = post(‘/rest/api/2/issue’)
.header(‘Content-Type’, ‘application/json’)
.body(
fields: [
project : project,
issuetype: [
id: issueTypeId
],
parent : [
id: issue.id
],
summary : summary
])
.asObject(Map)
// Get and validate the newly created subtask
def subtask = resp.body
// If the sub task created successfully return a success message along with its key
if (resp.status >= 200 && resp.status < 300 && subtask && subtask.key != null) {
logger.info(“Success – Sub Task Created with the key of ${resp.body.key}”)
} else {
logger.error(“${resp.status}: ${resp.body}”)
}
}
You can copy the script from here, or you can access this example script by clicking the Example scripts button when creating a new Script Listener.
Scheduled Jobs
Scheduled jobs are scripts configured to run on fixed time intervals. They can be configured to create subtasks, for example, every day for issues returned by a provided JQL query.
// Defined jql query
def jql = “project = TKCMP and type = Task”
// REST API that will return all issues for given JQL
def result = get(‘/rest/api/2/search’)
.header(‘Content-Type’, ‘application/json’)
.queryString(‘jql’, jql)
.asObject(Map)
// Save all issues returned by REST API in variable
def issues = result.body.issues
// Loop through all issues
issues.each { issue ->
// Save issue key and other field values
def issueKey = issue.key
def issueId = issue.id
def summary = issue.fields.summary
def project = issue.fields.project
// Create new sub-task
def resp = post(‘/rest/api/2/issue’)
.header(‘Content-Type’, ‘application/json’)
.body(
fields: [
project : project,
issuetype: [
id: 12345 // id of sub-taks issue type
],
parent : [
id: issueId
],
summary : “Subtask of: ${summary} (${issueKey})”
])
.asObject(Map)
}
After Scheduled job script is executed, you should be able to see Task together with its Subtask:
Workflows
You can use ScriptRunner workflow post-functions to automatically create subtasks when an issue is transitioned to a certain status.
Script for this would look the same as for Script Listeners. This is only an example, you should always modify it to meet your specific needs.
Jira Cloud REST API
Atlassian provides official public documentation for all REST APIs that you can use in external scripts. This is excellent for developers looking to integrate other tools with Jira or automate specific tasks like subtask creation.
You may notice that the API for creating issues is already used in the example ScriptRunner scripts. The same API can be used in your external scripts for creating issue subtasks.
When using Jira Cloud REST APIs, ensure you generate an API key for authentication. You’ll need to use this key together with your email address to authenticate your requests.
Conclusion
Automating Jira subtask creation can bring significant benefits to your team and organization, such as saving time and providing a clear overview of the required actions.
By setting up automatic creation for common subtasks triggered by specific actions, you reduce the risk of forgetting manual steps and improve your processes.
If you have questions or need assistance with setting this up, feel free to contact us.