Handling PropertyNotFoundException while evaluating script with ScriptEvaluationException

My issue is that i am getting org.camunda.bpm.engine.ScriptEvaluationException and org.camunda.bpm.engine.impl.javax.el.PropertyNotFoundException.

This is in a scenario when a property and its value is absent in the context/session intentionally and that the property is not initialised in the workflow.

So when the property is being sent like #{xyz} to a service task and when it is absent, customized camunda modeler is throwing this exception.

Possible workarounds as per my research is by adding a timer to this service task, but can someone please let me know if there is an actual solution or how to handle this?

I am open to share more info if required, this is an urgent requirement. so can someone please help ?

You could check if the property / variable exists in the execution scope before passing it to the service task using:

execution.hasVariable("xyz");

which returns true in case that the variable exists.

see also:

Hi,

Thanks for the solution but this is something that is kind of a workaround which we are following in other service tasks,

What i was looking for was if there was another way camunda has like a try catch or some mechanism to handle this error rather than initialising the variable in the context.

Also, i even tried to add timer boundary event which did not work as its failing with camunda exception.

Hello achuthak1,

Could you share your bpmn-file and your script task?
Integrating a try and catch mechanism should be possible also inside the script task.

Best
Mathias

Hi @klmathia,

It’s not actually a workflow designed through the Camunda Modeler; it’s a Camunda 7 integrated in-house app from my company, but the underlying mechanism is the same.

Let me elaborate on the problem.

I have a workflow in which I call a service task/service operation, which is essentially an XML file with components and models. My workflow calls this service operation and has two paths: success and error. The error path is configured to handle failure scenarios, including if the service operation takes more than n minutes to complete.

Now, when I run a scenario, this workflow gets stuck inside the service operation because I am manually deleting a row in the database, which is essentially a property inside the context. The service operation takes a property as input, which the workflow should send from its context, and this is the property I mentioned earlier as #{xyz}. So when this property is not found, Camunda throws the error mentioned above. However, for some reason, the workflow is not handling the failure/error path that we have configured to exit after n minutes.

The last solution you suggested is correct! If we initialize the variable/property before the service operation executes, the flow works like a charm. However, my problem is that I need to find a way to handle this PropertyNotFoundException so that no matter which property is absent in the context, the flow exits gracefully.

To summarize, the workflow is throwing a Camunda PropertyNotFoundException even before calling the service operation, as it is unable to find the property in its context. I need to find a way to handle this exception. Is there a way in Camunda 7 to handle this?

The workaround I tried by adding a timer boundary event to this service operation didn’t work. As I mentioned, the flow is not reaching the failure path and gets stuck even before reaching the service operation, indefinitely.