Programmatically how to find if the required postfunction has been fired or not

Jayashree Shetty
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 23, 2014

I have a canned script for task & subtask.

Primarily when all of the subtasks are in the required state i would want the task to move to the selected target state. Eg: Task needs to move to "Completed" state when all of its subtasks are moved to "Closed" state.

How can i achieve this in script.

For "Any" of the subtasks its easy. 

WorkflowUtils.actionIssue(params[Extra_SCRIPT] as String, parent, actionId, user, params).

This works fine.

But when i want to check all the subtasks, if they are in "Closed" state how can i do that. Because some of the tasks may be in some other state and we need to ensure if all the subtasks are in the 'Closed' state or not. Or is there a way by which i can get to know if the postfunction is fired or not for each subtask.

 

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 23, 2014

This is a little confusing - I'm not sure why you're asking "if a post function is fired".  When you run a transition, all the post-functions are run.  There's no firing or separate conditional processes, the post-functions on the transition are executed.  That's it.

However, if we step away from that, it seems you're trying to do a relatively common thing; when all the sub-tasks of an issue are closed, transition the parent.

JIRA does this automatically for you if you're using Agile, but if you want different behaviour than it uses (its rule is "when subtasks are all "done"") or you don't have Agile, then you'll need the following:

  • A workflow for the parent that allows you to close the issue from any other status
  • Either
    • A post-function attached to all sub-tasks that will read upwards to the parent, iterate through the sub-tasks, check their current status and issue the workflow action to push the parent through the close transition
    • A listener that will pick up the sub-task close event, read upwards to the parent, iterate through the sub-tasks, check their current status and issue the workflow action to push the parent through the close transition
Jayashree Shetty
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 23, 2014

Thanks Nic. Sorry for the typo. Yes all postfunctions are run when we run a transition. I have written a canned script. So this canned script basically has 2 scenarios. If task is moved then we need to move all the subtasks or if any/all subtask is moved then parent task needs to be moved. To achieve the first scenario is easy and its working for me. However for the second one i have a bottle neck which i mentioned above. The state can be any state not fixed to close state. I do not want to use any other script or postfunction. I want to cover all the scenarios in single canned script. I am basically providing an interface where user can choose what is the tranistion order. Is it Issue->SubIssue transition or SubIssue->Issue transition. This part of snippet is for the transition order Issue/Task to SubIssues/Subtasks if(transitionOrder=="Issue->SubIssue") { SubTaskManager subtaskmgr = ComponentAccessor.getSubTaskManager() Collection<MutableIssue> subIssues = subtaskmgr.getSubTaskObjects(currentIssue) if(doIt) { for(MutableIssue subIssue : subIssues) { User user = subIssue.getAssignee() WorkflowUtils.actionIssue(params[FIELD_ADDITIONAL_SCRIPT] as String, subIssue, actionId, user, params) } } }

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 23, 2014

That doesn't change what I wrote - in the second case, you need to read the current sub-task for it's parent, iterate through the other subtasks to check their status, and then call the appropriate transition on the parent.

Jayashree Shetty
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 28, 2014

Thanks Nic

Jayashree Shetty
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 28, 2014

Hi Nic to the description you gave above. In case i want this behaviour. If all subtasks are in complete state then transition the parent to implement state.How can i ensure that all the subtasks are in the same complete state. I do not want to hardcode this.I can change this complete to cancel or close depending on the requirement. How can i ensure this.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 28, 2014

You are going to need to write quite a lot for this. My pseduo-code above starts, but to expand on it a bit: When a sub-task issue type is updated * Read its parent * Get the list of all subtasks of the parent * For each of these subtasks ** Check the status ** If it is not "complete", then issue the relevant workflow transition(s) to get them into complete * Repeat for next subtask

TAGS
AUG Leaders

Atlassian Community Events