
Automatically CREATE SUBTASKS when a new story is created, and CLOSE the story when all subtasks are closed.
Part 1: Create one subtask | Part 2: Create multiple subtasks | Part 3: Close the story
Part 1 of 3: When a new story is created, automatically create a subtask for that story.
- Edit your workflow. Select the diagram view.
- Choose the initial Create transition. (The initial transition does not allow adding conditions but supports validators and post functions).
- Click Post Functions and then Add Post Function in the upper right corner of the list.
- Select the Create issue(s) post function and click Add.
- Leave Project as the default ("Same as current issue"), where the subtask will be created.
- For Issue type, select "Sub-task".
- For Parent issue, leave the default value ("Current issue").
- Optional: In the Link to new issue section, you can add a link type to link the parent issue and the subtask.
You can specify the value of fields in the new issue, but in this case, let's just supply the summary: In the JMWE script editor, update "CLONE" to the summary of the subtask:
QA sub-task - {{issue.field.summary}}
- You can optionally set additional fields and many other parameters. We'll skip these as we only need to create a new subtask.
- Click Add to add the post-function, publish your draft workflow, and check your work by creating a new issue.
Part 2 of 3: Automatically create MULTIPLE subtasks - development subtask, QA sub-task, and documentation subtask - when a new story is created.
Instead of creating several "create issue" post functions described above, create multiple subtasks all in one post-function. It is easier to build and maintain!
- Edit your workflow. Select the diagram view.
- Choose the initial Create transition.
- Go to Post Functions, and edit the Create issue(s) post function we created in Part 1 above.
- To create multiple subtasks simultaneously, navigate to the Multiple issue creation section and select "Create multiple issues."
- To specify an iterator, set up a list of values for creating new subtasks. Type in:
Development sub-task, QA sub-task, Documentation sub-task
- Go up to the Summary field and insert the values of the iterator - using {{it}} - which represents each value in the iterator section we set up in the previous step.
Click Update to save the modified post-function, publish your draft, and check your work.
Part 3 of 3: Automatically CLOSE the story when all subtasks are closed.
- Edit your workflow.
- Select the DONE transition. When the DONE transition is triggered on the last subtask to be closed, then the parent story should be automatically closed.
- Go to Post functions, and click Add post function.
- Select Transition issue(s) post-function, and click Add.
- For Target issues, select “Parent issue of the current sub-task.”
- Under Transition, click the Transition picker button.
- Select our workflow and the transition we want to trigger, which is "Done."
- To add, click on Use Transition ID, which is safer than using the Transition Name (in case the transition is renamed).
- Click Add to complete the post-function configuration. This will ensure that when the DONE transition is triggered, it will also trigger the DONE transition on the parent task.
But that's not all! Note that we have not yet specified that the parent issue should only be closed if all of the subtasks are also done. Let's add a condition to the Transition issue(s) post function for that.
- From the Post Functions tab, edit the Transition issue(s) post function we created above.
- Click Advanced options near the bottom of the screen, then click Settings.
- Check the box to run this post-function only if a condition is verified.
- In the script editor, enter the following script:
{% set stories = targetIssue | subtasks %}
{% set trigger = true %}
{% for story in stories %}
{% if story.fields.status.name != "Done" %}
{% set trigger = false %}
{% endif %}
{% endfor %}
{{ trigger }}
- Publish your workflow and check your work.
Read the documentation | Explore usage examples for JMWE Post Functions