I would like to be able to generate a notification when a number of sub-tasks under the same parent all reach a certain status. The number of sub-tasks can vary depending on how many exist under the parent, but not all sub-tasks under the parent are able to reach this status (different workflows). Also the order of sub-tasks reaching the status is random.
I tried using a counter system with Automation and JMWE post-functions that would increment a counter field when a sub-task was created, and a different field when it reached that status (hoping that I could trigger the notification when one counter field equalled the other counter field), but the problem was that we often create sub-tasks in bulk, so the counters are not able to cumulatively sum with the automations or post-functions from several issues occurring at the same time.
I have scriptrunner installed so I have a feeling the notification system could be achieved with a groovy script but I at my level of expertise with groovy I would need some code that can at least read sub-task statuses to begin and then I can modify for my use case. Can anyone help me with that?
Hi Lenny,
with JMWE, you don't actually need to create a counter field, you can easily count the appropriate sub-tasks during the transition, based on whatever criteria makes sub-tasks eligible or not (I'm guessing the issue type). And you also count the sub-tasks that have actually been through the particular Status, using the fieldHistory filter for the Status field.
If you describe your use case in more details (in particular, which sub-tasks you want to take into account), I can help with the Conditional execution Nunjucks script.
Hi David, thanks for your quick reply.
Let's say I have 6 issue types, call them A,B,C,D,E,F. They may or may not exist under a given parent issue. If any of them do exist, then unless they are in status = Cancelled, they can reach the status = "Data Ready".
Since you are suggesting a conditional execution script I am guessing this would be a post-function, that would be placed in the transition for all of those issue types when transitioning to "Data Ready" and would be checking on all other sub-tasks under the same parent.
The end result would be a notification generated only if all eligible sub-tasks (Cancelled excluded) are in the "Data Ready" status. Thus I would expect the post-function to run conditionally and not generate the notification for all sub-tasks transitioning to "Data Ready" status besides the last sub-task, which would trigger the notification.
Let me know if this is along the lines you were suggesting.
Thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, that's what I was thinking of. You could use the "Email Issue" post-function on the "Data Ready" transition of sub-tasks to generate the notification email, and use conditional execution to determine when the email needs to be sent.
Let me try to summarize the condition to see if I got it right: every sub-task of the parent of the sub-task being transitioned to Data Ready must be either in the "Data Ready" status or in the "Cancelled" status. Is that correct? Or could some issues be _beyond_ the "Data Ready" status and still be considered as "Data Ready" (meaning they should allow the notification to be sent out)?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The sub-tasks may be in other statuses, however if one is in "Cancelled" status, then it can be discarded from the criteria for sending the notification (a sub-task that is Cancelled will never reach Data Ready, so it does not need to be evaluated).
And yes, issues beyond the Data Ready status should count, and allow the notification to be sent out.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So basically you want to send a notification when the last sub-task reaches the Data Ready status, even if other sub-tasks already moved beyond the Data Ready status, and just ignore sub-tasks that are currently in the Cancelled status (which is a "terminal" status). Correct?
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.
Then I believe this is what you're looking for:
{% set passes = true %}
{% for subtask in issue | parentIssue("subtasks") | subtasks( "status" ) %}
{% if subtask.fields.status.name != "Cancelled" and subtask.fields.status.name != "Data Ready" and
not (subtask | fieldHistory("status") | find("from_string","Data Ready")) %}
{% set passes = false %}
{% endif %}
{% endfor %}
{{passes}}
Unfortunately, I cannot fully test it, so let me know if it doesn't work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi David,
The script works great so far after testing with multiple scenarios, thank you.
The one thing that I am not sure if I made clear is that there are other sub-task issue types that should be ignored completely for this script, as in there is a defined set of issue types that this script should check and no others. Is that possible to implement in the script? Let's say the list of issue types was A,B,C,D,E,F.
Thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh, sorry, you did mention it but I thought it was related to the statuses...
Ok, try this then (you'll need to adapt it of course):
{% set passes = true %}
{% for subtask in issue | parentIssue("subtasks") | subtasks( "status,issuetype" ) %}
{% if subtask.fields.issuetype.name in ["A","B","C","D","E","F"] and subtask.fields.status.name != "Cancelled" and subtask.fields.status.name != "Data Ready" and
not (subtask | fieldHistory("status") | find("from_string","Data Ready")) %}
{% set passes = false %}
{% endif %}
{% endfor %}
{{passes}}
This will only check the status (past or present) of sub-tasks of type A, B, C, D, E or F (and ignore all others). If you wanted the opposite (ignore A B C D E F), add "not" right after "if".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for all your help, David. I have tested the script against all the situations I can think of for now and it passed every time. I will mark this as the accepted answer.
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.