JMWE for Jira Cloud: Configuring post functions

configuring-post-functions
Appfire

Appfire

Nov 22, 2021

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.

Jira workflow screen showing the 'Create issue(s) post-function' setup with a focus on the 'Sub-task' issue type in the workflow transition settings

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}}

Jira configuration page where a custom script sets the summary for a new sub-task using the syntax '{{issue.fields.summary}}' in the 'New value' field

  • 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.

Jira task view highlighting a sub-task named 'QA sub-task - Update API endpoints' created under the main task titled 'Update API endpoints


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.

Jira post-function settings screen for 'Create issue(s)' function, with options to edit, move, or delete the function highlighted at the top right

  • 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

Jira workflow configuration screen showing an iterator setup for creating multiple sub-tasks with labels like 'Development sub-task' and 'QA sub-task' using a comma-separated list

  • 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.

Jira post-function configuration where a custom script sets the summary for a sub-task with the syntax '{{it}} - {{issue.fields.summary}}' in the 'New value' field

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).

Jira administration screen for selecting a transition within the 'Transition issue(s) post-function,' highlighting options for workflow and transition selection

  • 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.

Jira post-function screen showing a conditional execution script that checks the status of subtasks before triggering the post-function

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 documentationExplore usage examples for JMWE Post Functions

Appfire

Appfire

Appfire is the leading global provider of software that enhances, extends, and connects the world's leading platforms to make work flow any way teams want to work, from planning to product ideation, product development, project delivery, and beyond. Articles posted by Appfire are written by internal team members.

Loading...