Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Scenario

When all related Sub-tasks for a Story are completed and closed, automatically transition the Story to Done.

Resolution

This solution uses the Transition issue post-function and requires conditional execution using a Nunjucks script. When an issue is closed, the script refers to the related Story of the issue being closed (if there is one), and checks the status of all sub-tasks for that Story. If it finds a sub-task that has a status other than “Resolved”, the post-function will not run and the Story will not be transitioned. If all sub-tasks for the related Story are closed, the post-function will run and the Story will be closed.

Note: this configuration is an example of a post-function executing on a target issue versus the current issue. The current issue is the issue that triggers the post-function to run; the target issue is the issue that will be updated by the post-function. The post-function configured below will run whenever any issue is closed, but it will trigger a transition on a different issue than the one that initiated it.

Info

You are viewing the documentation for Jira Data Center/Server.

Switch to Jira Cloud.

On This Page

Table of Contents
minLevel1
maxLevel2
outlinefalse
typelist
printablefalse

Steps to Create

1. Add Transition issue(s) post-function

  1. Log into your Jira instance as an Administrator.

  2. In the upper right corner of the window, click Settings ( ⚙️ ) and select Issues.

  3. In the left-hand sidebar, click Workflows.

  4. From the list of Workflows, click the Action button ( (blue star) ) for the appropriate workflow and select Edit.

  5. Edit the transition:

    1. When viewing the Workflow in Diagram view (Figure 1, right), select the Transition and click the Post Functions link. Click Add post function at the top of the list of existing post functions.

    2. When viewing the Workflow in Text view, click the name of the Transition then select the Post Functions tab. Click Add post function at the top of the list of existing post functions.

  6. Select Transition Issue(s) (JMWE app) from the list of post-functions and click Add.

Image Added

2. Configure the post-function

When using the Transition issue(s) post-function, the target issue will be moved through its workflow based on the post-function configuration. Generally, the post-function can be configured with a prioritized list of transitions to trigger and it will move the issue through the first transition that is appropriate to its current status. In this scenario, the post-function is configured with a single transition - Done - and uses conditional execution to only execute the post-function under very specific circumstances. See Transition issue(s) for more information.

Note: The configuration below has a few pre-requisites in order to function as described.

  • The parent Story is in a status immediately preceding the Done status, or the transition to Done is available from all other statuses.

  • The Nunjucks Groovy script included under Conditional execution checks for a status value of “Resolved” to determine if each sub-task is closed. This value will need to match your status value for the Done status.

Set the following configurations:

  1. IssueTransition(s) to operate on (Point 1, Figure 2, right) - Set Target issue(s) to Parent issue of the current sub-task. Transition(s) (Point 2, Figure 2, right)

    1. Set Transition(s) to Trigger on one of the following transitions.

    2. Set Transition name or ID to Done, or the appropriate transition to move the issue to a closed status. Click Transition picker to open a window where you can search for a specific transition.

  2. Run As Issue(s) to operate on (Point 2, Figure 2, right) - Set Target issue(s) to Parent issue of the current sub-task.

  3. Options (Point 3, Figure 2, right) - Set as needed; it is recommended to leave the default Add-on user value unless required for specific reasons.

  4. Transition Screen (Point 4, Figure 2, right) - Set as needed.

    1. If any fields are required to transition the issue, add them here.

    2. In the example (Figure 2, right) the Comment field has static text added to the parent Story - This issue has been closed because all sub-tasks have been resolved.

    3. Set Comment visibility as needed.

  5. Run As (Point 5, Figure 2, right) - Set as needed.

  6. Conditional execution (Point 56, Figure 2, right) - Enter the following:

    1. Check the box Run this post-function only if a Only if condition is verifiedtrue.

    2. In the Condition field, enter the code:

      Code Block
      languagenone
      {% set subs = issue.fields.parent.key | subtasks("status") %}
      {% set trigger = true %}
      {% for sub in subs %}
      	{% if sub.fieldslinkedIssue.subtasks.stream().allMatch { it.status.name !== "Done" %}
          	{% set trigger = false %}
          {% endif %}
      {% endfor %}
      {{ trigger }}
    Delayed execution (Point 6
    1. 'Done' }
  7. Error Handling (Point 7, Figure 2, right) - Set as needed.

  8. Click Add.

Image Added

3. Publish and Verify

Include Page
MWECS:[Includes] Use Cases - Publish and TestMWECS:
[Includes] Use Cases - Publish and Test
Image Added

Panel
bgColor#E3FCEF

You’re done!

Now, when a sub-task is closed, Jira will check the parent issue to determine if it has any remaining sub-tasks that are open. If it does not, the parent issue will be closed!