0
votes

How can I implement more complex expression in a flow's condition? Simple conditions like:

${i > 0}

are handy and great but there are other times I need to do something a little more complex like:

${deadLine.after(now)}

Assuming deadLine is an object of type Date already defined in process instance and now means new Date(). How can I implement such expressions in a flow's condition? In Java I can:

ExpressionFactory factory = new ExpressionFactoryImpl();
SimpleContext context = new SimpleContext(new SimpleResolver());
factory.createValueExpression(context, "${deadLine}", java.util.Date.class).setValue(context, new java.util.Date());
factory.createValueExpression(context, "${now}", java.util.Date.class).setValue(context, new java.util.Date());
ValueExpression expr1 = factory.createValueExpression(context, "${deadLine.after(now)}", boolean.class);
System.out.println("Result = " + expr1.getValue(context));

But how can I do the same in a flow's condition?

1

1 Answers

2
votes

Given you have a process variable named deadLine that is a java.util.Date object, you can write:

${deadLine.after(now())}

This works because Camunda provides a function now in the expression context [1].

There are several other ways to evaluate complex decision logic, for example:

  • invoke a Spring or CDI bean that codes the decision in Java
  • Use a script/service task or execution listener before the condition is evaluated that executes the decision logic and stores the result in a boolean process variable

I recommend reading this: http://docs.camunda.org/7.3/guides/user-guide/#process-engine-expression-language-variables-and-functions-available-inside-expression-language