Validation from external resouces

I have a modeler and I have given condition on sequence flow where i have used expression like ${Status==“A”} . but I wanted to select External Resource like java or javascript to provide validation.
I need to know how to do these things using both option provided in condition tags of sequence flow like inline script and external resources.

expression

Hi @abhi1o3,

Have a look at below link from camunda docs

https://docs.camunda.org/manual/latest/user-guide/process-engine/scripting/#use-scripts-as-conditions

Keep in mind that the returned value/statement of your script should be evaluated to boolean value.

have you checked docs? Scripting | docs.camunda.org.

As inline script example you can use something like:

// groovy script
println “seq condition check…”

if (execution.getVariable(“dummy”)) {
return true
} else {
return false
}

1 Like

how to do using external resources as java?

how to do validation using java?

Hi @abhi1o3,

In the case of sequence flow condition, you only have the option to use one of JSR-223 compatible scripting languages.

Read more about scripting in below docs
https://docs.camunda.org/manual/latest/user-guide/process-engine/scripting/

And below docs show where you could use Java code
https://docs.camunda.org/manual/latest/user-guide/process-engine/delegation-code/

you means, we cannot use java for validation ?

You could use ExecutionListener to execute Java code on the event of taking a transition “sequence flow” instead of sequence flow condition.

See below link
https://docs.camunda.org/manual/latest/user-guide/process-engine/delegation-code/#execution-listener

I have a gateway and based on condition, it should go to the specifc user task .
so for that I want to use java for validation instead of expression.
How it can be done using ExecutionListener?
I am sharing my modeler, please have check on that.CustomerOnBoardfinal.bpmn (5.4 KB)

May we know more about your case? Where should validation occur?

In that modeler you can see Exclusive gateway which have two direction one is proCode == ‘01’ and other one is proCode == ‘02’ . so based on these value of procode , I need to navigate to specific user task either SEC_APP or PROD_PREF. I can do this using ‘Condtion type’ as Expression on each Sequence flow and put that expression. but I need to know how to do using External Resource as java.?

just use service task to populate proCode variable with java, before gateway or use exec listener as hassang suggested.

what I need to write in exec listener and where i will use that? is that on each user task

Hi @abhi1o3

We couldn’t name it validation. It is kind of routing based on condition.
Using condition type as expression is the best fit implementation.

I have used execution listener to take transition but what i need to set on condition type as expression in sequence flow.

If u are looking of how to use java in condition, where only scripting or expression available, then you can import your java class into groovy. Not sure why youd wanna do it but it’s possible.

can we write any script on ExclusiveGateway itself so that screen to be navigated based on the condition given on one script only which is there in ExclusiveGateway?

Hi @abhi1o3,

It’s not stated clearly in the docs, but you can use Beans in expressions on sequence flows as well, if you have Spring or CDI on hand: https://docs.camunda.org/manual/7.9/user-guide/process-engine/expression-language/#external-context-variables-with-spring-and-cdi.

For example you can reference this class:

import javax.inject.Named;

@Named
public class Decider {

  public boolean decide(String value) {
    if (value.equals("yes")) {
      return true;
    } else {
      return false;
    }
  }
}

with this expression in the process model: ${decider.decide(up) == true}. up is a process variable defined in a further activitiy.

I’ve tried it on the Wildfly distro.

Hope this helps, Ingo

3 Likes