Intialize and Set process variables to runtime to make them to be used by xor sequence flow evaluation

Hi @all,

I wanted to know if I can intialize and set process variables to runtime in order to make them to be used for an XOR evaluation?

My process model inlcudes this pattern:

The variable ‘historyExisting’ should be intialized in Task ‘Look up for credit history’ and be setted to true or false. The xor should then recognize this variable the corresponding sequence flow evaluation…

Can anyone help me and give me an example to implement the logic behind this pattern?
Many thanks in advance!

Kind Regards, rlafraie

Hi @rlafraie,

Sure you can :slight_smile:

Not a complete example, but at least something to start with:
You could implement a custom JavaDelegate class (e.g. MyHistoryExistingCheckerJavaDelegate) that sets the variable historyExisting. In the documentation about Delegation Code you can see an example of how to retrieve a variable, transform the content string of the variable to upper case and then setting the variable. Finally, you just need to add the path to the custom delegate class to the service task Look up credit history.

Best,
Johannes

Thanks for the answer @JoHeinem,

Do I explicitly have to create or initialize process variables in Task ‘Lookup credit history’ (in runtime) for example or is it implied in the setVariable() method?

Relating to the second question and the logic of an xor evaluation:

Lets say for example I have specified the expressions of the outgoing sequence flows after the xor with ‘${historyExisting==true}’ and ‘${historyExisting==false}’. In the Task ‘Lookup credit history’ I want to create this process variable called historyExisting (boolean). Does Camunda recognize this variable at runtime in order to include in the evaluation of the stated expression? - What I have to do if not?

Kind Regard, rlafraie

Hi @rlafraie,

Sorry, but I don’t get the question. What do you mean by “implied in the setVariable() method”?

Yes :slight_smile:

Best,
Johannes

Hi @JoHeinem,

Excuse me for the misunderstanding. What I meant is when I wanted to create the process variable at runtime (e.g. historyExisting), is it enough to use the Delegate execution.setVariable method or do I have to use an statement like createVariable() or something. To make it clear: historyExisting shall not be a Variable which I create by startProcessInstance.

Hi @rlafraie,

It should be enough to use the execution.setVariable() method.

Best,
Johannes

If in doubt, just try it out in a unit test. If you start with the unit testing template, you are up to speed in no time and you’ll gain experience with how to test your processes properly.