Execute a groovy script AFTER the transition


I've got a problem during my transitions :
I wrote a groovy post-function script that is executed during the closed transition of a child issue.
This script has to verify if all the other children of its mother are closed. If they are, the mother is put into a new status (and the current child close), otherwise, just the current child is closed.

But I have another requirement : when a user wants to put the mother into the new status (the same as precedent), a transition condition has to verify if all the children are closed.

So, the first script works, but when i add the second one into the mother new status transition, and when i want to close a child, the first script cannot put the mother into the new status because the second script detects a child not closed (the child is not closed yet).

How could i do ?

Thanks !


2 answers

1 accepted

I found a solution :

My first script (executed in the child close transition post-function) was executed BEFORE the issue passed in closed state. And that why the other script, executed when the mother have to be put in its new state detected the child not closed.

So, i put the first script in a transition condition to leave the closed state (i've got an administrator state in the child workflow, that be able to go everywhere from anywhere ...). Finally, the script is exetuted AFTER the child passed in closed status, and the mother script detects the child closed.

Congratulations, that's it

Have a chocolate!

Thank you Jamie for your answers :)

Cool, well done. Enjoy that chocolate ;-)

0 vote

I can't really get my head around your problem. Have you written your own code?

Perhaps you could use either or both of https://studio.plugins.atlassian.com/wiki/display/GRV/Built-In+Scripts#Built-InScripts-Allsubtasksmustberesolved and https://studio.plugins.atlassian.com/wiki/display/GRV/Built-In+Scripts#Built-InScripts-Transitionparentwhenallsubtasksareresolved.

Is what you are saying that, when you close the subtask, the parent should also close, but it doesn't because your condition is saying a sub-task is still open? If so try changing the order of events, make your post-function on the child run last.

Or you could detect if a post-function is running and ignore the condition, maybe by making the condition only valid for non-admin users, or by setting a session variable or thread-local or something. I'm sure there is an easier way than that though.

Thank you for your quick answer.

Is it easy to define a session variable ? I think it's the best way to solve my problem ...

Is what you are saying that, when you close the subtask, the parent should also close, but it doesn't because your condition is saying a sub-task is still open?

Yes it is. My child post-function script verifies if all other mother children are closed, and if it's true, it closes the mother. But in the close transition of the mother, there is a script condition that verify if all children are closed : so the first script calls the second (when all other children are closed) but the second script detects an opened child (the child who wants to be closed).
So i want my first script (post-function script on the child close transition) executed AFTER its status changement, because when the second script will be called, it will detects the child closed, and not opened ...

Sorry for the triple post ... :)

Jamie, I could use the ScriptManager, and get the current scripts (I suppose there is a getScriptObjects() method, or something), test it (is there 2 scripts running ?) and then make the condition non-valid, right ?

If the post-function is really the LAST post-function, you should not get this problem. Is it last?

Other methods are too complicated, and are working around an issue you should not really have, as far as I can tell.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

236 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you