state machine's onEnter is not triggered when state is changed in a state transition

I have a state machine defined for subtasks to check if all the subtasks are resolved, change the parent's state to 'To Verify'.

And in parent type's state machine, there is onEnter for 'To Verify' state which will do some notification work.

The problem is that when I resolve all the subtasks, the parent's state is changed to 'To Verify' but the onEnter function is not executed. However, if I manually change the state of parent to 'To Verify', the onEnter is working.

The code is as follows:

function checkAllSiblings(ctx) {
var parent = ctx.issue.links['subtask of'].first();
var subtasks = parent.links['parent for'];
var unresolvedTask = subtasks.find(function(issue) {
return !issue.isResolved && issue.id !== ctx.issue.id && issue.isReported;
});
if (!unresolvedTask) {
parent.fields.State = ctx.State['To Verify'];
}
}

// in subtask's state machine
Done: {
onEnter: checkAllSiblings,
transitions: {}
},

// in parent's state machine
'To Verify': {
onEnter: function(ctx) {
notifier.notifyTest(ctx.issue);
},
// transitions and other stuff
},
1 comment
Comment actions Permalink
Official comment

Hello,

This is designed behavior: State Machines are triggered only if you change the corresponding state manually (i.e., via UI, via commands or via REST), but not via workflow rule. As a workaround, I suggest you send additional notifications from the rule that sets the parent's state to "To Verify".

Please refer to the JT-10310 task for more information. Should you have any further questions, feel free to contact us.

 

Please sign in to leave a comment.