Is there a way to make a variable optional while process instantiation


I have process where assignment can be dynamic i.e. either to individual user or a group.

In my process I’ve two variables camunda:assignee="${userAssignment}" and camunda:candidateGroups="${groupAssignment}".

As only either of the value will be part of request payload to initiate process, it fails with value is expected.

ex: if I pass userAssignment value, then it fails with groupAssignment variable is expected.

So is there a way to ignore.

Suhas Madap.

Hi @revsmadap

Does that happen even if you pass all of the variables setting one of them to null?
If yes. Then try below solution.

As a simple solution (may be not perfect) you can duplicate the task and add an exclusive gateway before them (the 2 tasks).

Task 1 has camunda:assignee="${userAssignment}"
Task 2 has camunda:candidateGroups="${groupAssignment}"
The exclusive gateway will direct the execution flow based on the value of userAssignment/groupAssignment

In case userAssignment has a value, execution will go to Task 1
Otherwise (groupAssignment has a value), execution will go to Task 2

You can also have an ExecutionListener on the start event of the process and initialize any variable that was not supplied.

1 Like

I believe Thorben’s solution is the better one.
Use an execution listener on the start event to initialize variables that may be needed later.

I make it a practise to ALWAYS include a script task immediately after the start event to initialize variables the process may need. This is effectively the same as Thorben’s solution so pick your poison.