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.
Community moderators have prevented the ability to post new answers.
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:
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) } } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Nic
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.