SimpleWorkflow Branching with constraints issue

Hello everyone.

First off I’m not to sure whether or not I should post this here. If it belongs elsewhere please let me know.

Anyways, I’ve been using simpleworkflow for my workflow needs and it’s been great but I’ve run into a little issue recently.

Here’s the problem. I would like my workflow to branch out into one of two choices. The setup for the workflow is as follows (it’s incomplete, just showing what is relevant to the problem)

array(	'id'=>'start',	'transition'=> 'stepTwo,cancel'),

array(	'id'=>'cancel','transition'=>'stepThree',


array(	'id'=>'stepTwo',	'transition'=> 'completed',


The idea being that either ‘cancel’ or ‘stepTwo’ return true and the workflow proceeds onto that branch. I have however run into the problem in which swGetNextNodes() only returns an array with the first of the two “next nodes” (in this case ‘stepTwo’). So only the constraint on that Node is executed and if it returns false then it never proceeds to ‘cancel’.

Is this desired behavior? If so maybe I’m missing some of the basics. Is there a way to fork on a simple true/false.

I would also like to add that I would rather not set the constraints directly into the transitions with a ‘transition’ => array(‘stepTwo’ => ‘$this->needsConfirm()’,etc…)

Thanks in advance for your help.

Hi pommeVerte

I’ve seen you post and reply asap (I’m at work right now) … what you describe seems to be an unexpected behavior. If stepTwo is returned but its associated constraint fails … well it should not have been returned in the first place.

I’ll take a deeper look later on and let you know …



Hey there Raoul. Thanks a lot for taking the time to look into this. If you need any additional information feel free to ask.

Hi [color="#1C2837"]pommeVerte,[/color]

[color="#1C2837"]I read more in detail what you wrote, and I’ll like to be sure I understand well.[/color]

[color="#1C2837"]First you mention the method swGetNextNodes(), but I assume you mean swGetNextStatus() as swGetNextNodes() doesn’t exist. That being said, here is how swGetNextStatus should work when it is called for a given model instance.[/color]

Please note that a constraint is evaluated at the time the swGetNextStatus() is called and so, constraint value may change between two calls … (constant constraint value would not have any sense wouldn’t it ? )

Now let’s what you describe…

If only one node is returned this is because the other one (‘cancel’) has a constraint which was evaluated to false. Logically, if ‘cancel’ constraint fails, the ‘stepTwo’ must succeed (I mean, one is a NOT of the other one right ?).

Up to now, I see no problem …

The constraint on the node returned by swGetNextStatus() has already been evaluated, and moreover it has been evaluated to true, optherwise, this node would not have been returned by swGetNextStatus().

Sorry, but in the end I don’t see any problem …or maybe I didn’t understand what you describe as a problem … So tell me what you think.

Regarding your last comment, declaring a constraint like you suggest would be a big change in the way the extension works. By linking the constraint to the transition and not to the node itself, things could get quickly very complicated (to define, and then to use). My goal when I wrote this extension was to keeps things as simple as possible … maybe I didn’t succeed 100%, but I tried ;)

I hope that you’ll be able to use this extension and that it will save you time …


Sorry I meant getNextNodes(). swGetNextStatus() actually returns an empty array (because the constraint on ‘stepTwo’ returns false), and the constraint on ‘cancel’ is never executed. When I traced it back I found that _tr in swNode was not populated with the ‘cancel’ Node. I don’t know why this is and was hoping someone could recreate this issue.

ok ok … now I understand better… If stopTwo is not returned (because contraint fails), then ‘cancel’ should be returned.

I’ll try to reproduce this, and let you know …



Hey Raoul. Thanks a lot for the help but it turns out the mistake was on my part. SimpleWorkflow works as intended, I just got confused because the application I picked up had a certain complexity.

Thanks again, great extension, we’ve been loving it here.

Take care, I hope you have a nice day.