Are Input Variables from a Service Task re-evaluated after a retry

I have the following scenario:
My REST API wants a Request-Id in the header to ensure idempotency.
So I want to generate the UUID in the input variable.

The Question is now, if the request fails and there is a retry from Camunda, will then the input variable be re-evaluated? Or in other words - is the UUID still the same?

If you generate the UUID in memory when invoking the service, a retry will result in a new UUID. If the UUID you are passing is a persisted (non-transient) process or task scoped variable, it will be re-used. So for your case, if it’s not already a variable, you could for instance create it as a locally scoped variable in an ExecutionListener at the start event of the task and then just use that variable in the call to ensure you use the same value on each invocation. Make sure the task is async before in that case.

1 Like

@tiesebarrell , thanks for the response. So to summarise your answer:
If I generate the UUID as Input Variable it will create the variable every time.
If I generate the UUID in the Execution Listener (start) it will create the variable just ones.

Exactly, that’s what I meant.

1 Like

Doesn’t the listener get executed each time the job is executed? I.e. wouldn’t a new UUID be generated on each retry?

IIUC, in order to have the same UUID, one should generate it in a previuos step (and save as a process variable), and have an async point somewhere before the step in question (e.g. mark the step as “async before”).

1 Like

@fml2 , thanks that is actually what I did - as it was not possible with input variables.

But now we have 2 different opinions - so we need to figure out which one I should mark as solution :upside_down_face:.

You can make a small project and find out.

The listener is executed when the task is started, so precisely once for each execution. Indeed, if you need that variable to be consistent across all executions, you cannot set it in a start listener of the same task. My mistake, sorry. You have to set it either in a task before (using, for instance, a listener) or in a listener on the sequence flow that flows into the task.

https://docs.camunda.org/manual/7.15/user-guide/process-engine/transactions-in-processes/#understand-asynchronous-continuations

1 Like

This answer I can confirm. This is nearly the same as I said earlier.

1 Like