Modelling output variable changed events

Hi am new to BPM and Camunda; not sure if this is right forum to question. Have a question regarding events for below sample workflow(For simplicity have used only one output variable per user task) ; based on Task1 variable1 value decision forks to either Task2 or Task3.

Question. When in Task 2 or Task 3, if variable1 value is changed, is it possible to move the current activity to Task 1 via signals/events, something like below

Hi,

At the moment, your process is not really event centric and thus variable 1 can only be changed by Task 2 or Task 3. In addition, either task 2 or task 3 must complete in order to effect a change on variable 1. Hence you really need to perform this process flow test after the tasks have completed. Given this is the case, it would be easy for either task 1 or task 2 to set a flag if they change the value of variable 1. Hence in this case, it would be very easy to test this value and route the process flow using an Xor gate as per the process diagram below.

We could consider the use of conditional events etc, however I like the principle of keep it simple and no simpler than it needs to be. Now if the value of variable 1 can change outside the influence of the process flow, then thats a different use case and pattern…

regards

Rob

1 Like

Thank you Rob for the detailed info. Sorry missed out to mention earlier the variable1 could be updated from outside actions. When workflow is in Task2/Task3, any external events could trigger variable1 value change; which would fall in the second scenario as you have mentioned.

Hi Kiran,

OK, given that variable 1 can be updated by outside (relative to your main process) actions, I would use a message event to model when the variable changes. In particulr, you will need interrupting boundary message events to get the behaviour you are after. See process model below.

Note that the update process does not necessarily have to run in the process engine. All thats really required is for some external context to inject the message event into the engine (eg REST API).

Also given the same event cold interrupt either task, another possibly more elegant way of modelling this is as per below using an inline sub-process.

regards

Rob

1 Like

Hey guys,

I think it will be much easier to use the conditional events for that. (Available on 7.6)

On the conditional event you can define that the event should only be evaluated on a special variable name and also on special event like update. If the condition for that event is ${true} it will fire every time the condition is evaluated.

  <bpmn:conditionalEventDefinition camunda:variableName="variable1" camunda:variableEvent="update">
    <bpmn:condition xsi:type="bpmn:tFormalExpression">${true}</bpmn:condition>
  </bpmn:conditionalEventDefinition>

The process could look like this:

1 Like

Hi Zelldon,

I considered the conditional event approach, however you still need something to modify the variable value to trigger evaluation of the condition? Hence given the modification is coming from outside the process, a message event which updates the value seemed appropriate. Hence given you need to inject a message event in order to change the variable value, it made sense to also use that as the trigger.

Thus in your suggested approach, how does the process variable actually get modified to trigger evaluation of the condition?

rgards

Rob

Hi Rob,

its this easy: https://docs.camunda.org/manual/7.6/reference/bpmn20/events/conditional-events/#set-variable-from-outside.

Cheers, Ingo

3 Likes

Thank you Rob, Zelldon, Ingo will try out the approaches mentioned.

Hi,

Where can we write the code to change variable value as mentioned in the link? is This for delegation class implementation/external implementation for any of the tasks?

Thanks,
Sindhu.