Is there any way to throw a bpmn error via feel expression in a script?

Below is the sample feel expression configured in the script task …in else part i want to throw error

if string length(name) > 5 
then "Valid" 
else //Here i want to throw some error which can be caught by boundary error

Below is the sample model, i have attached the BPMN as well.
validate inputs.bpmn (4.8 KB)

Hi @Anmol_Gupta
You can use an exclusive gateway following the script task. (In the case of simple FEEL expression, there is no need to have a script task. You can define the condition on the outgoing flow itself)

1 Like

Thanks @hassang for responding. I get there can be alternate options to do it. My expression was bit complex so for a cleaner representation i just posted a sample.

To reframe the question, does feel expression in camunda script supports the ability to throw BPMN exceptions ?

There’s a feel function you can use to throw a BPMN Error

bpmnError("ERROR_CODE", "Error message", variables)

you can also throw the error as part of a larger expressions

if response.body.status = "failed" then 
  bpmnError("ERROR_CODE", "Error message", response.body) 
else 
  null

I believe the bpmnError function is specifically designed to work with the error expression of out-of-the-box connectors. In my opinion, its value is limited when used in a script task, as you have complete control over the script’s execution. In contrast, it is more useful with connectors like a REST connector, which handle calls to external services where you have no control over the service’s implementation.

Hate to be that guy to my friend Niall :sweat_smile: but @hassang is correct - the bpmnError() FEEL function is only available in the Connectors runtime currently (and therefore only available in the error expression field of a Connector).

Can you share a bit more about your particular use case @Anmol_Gupta? I can take this feedback to our product team for consideration.

1 Like

@nathan.loding - we often use feel script tasks in low code environments rather than workers…

At times the ability to throw a bpmnError would be elegant and convenient…

The current alternate is to use magic values in process variables and route using a decision gate…

Regards

Rob

1 Like

Thanks @Niall and @hassang for replying. I tested and was not able to use bpmnError in script task.

Hi @nathan.loding as @Webcyberrob mentioned, when it comes to things like things like complex data manipulation and validations its preferable to write the logic in in-built script as its low code and second we don’t have overhead to manage another job worker.

would be helpful if this can be part of product. Also is there any way we can open some jira or something to provide suggestions for features ?

2 Likes