Pass retry counter to service call (using expression language syntax)

I’m trying to do some custom error handling for a service task based on which retry it is in. The behaviour would be: Use the regular retries on service tasks unless it is the final retry then I want to throw a bpmn error to trigger an error handling path. For this I would need to pass the retries from the job to the service task. Ideally something like: ${my.serviceTask(execution, job.retries)}. Does anyone have an idea on how to do this.

@Thomas1 convert this to a expression lang:

execution.getProcessEngineServices().getManagementService().createJobQuery().executionId(execution.getId()).singleResult().getRetries()

You can do ${execution.getProcessEngineServices()....} in your expression

It’s a shame that you have to do a query to find the job you’re currently in.

@Thomas1 based on your use case, it seems what you are trying to do is what a Incident Handler is designed for.

Here is a script implementation of a handler: https://github.com/StephenOTT/camunda-incident-handler-nashorn-js

The handler will execute when you have a failed job (it tried the default 3 times and its still in a state of failed). So if you are trying to do something when N number of tries have failed, then you are talking about a incident handler.

If you want to try 3 times and use a BPMN error, I would recommend that you look at doing Multi-Instance Sequential: and then you set a Completion Condition. So if the first or second processes complete, then you can not worry about the left overs: https://docs.camunda.org/manual/7.10/reference/bpmn20/tasks/task-markers/#multiple-instance

You can then execute your BPMN error handling and when the loopCounter reaches your desired value then you throw your BPMN error.

Updated above for better usage