Execute input variable as expression


I’m trying to define a generic BPMN workflow (“CommandExecutor”) that can be reused in other workflows by invoking it as “call activity”. This generic workflow is supposed to execute a command (basically publish an event), then wait for another event as response → evaluate the response and either complete successfully or with an error. If a response is not received for a specified amount of time - also complete with an error.

I am trying to make the CommandExecutor configurable through input variables - so that any other workflow calling it can set the desired parameters: [name of the event to send, parameters of that event, name of the response event to listen for, timeout duration, expression to evaluate the success/failure of the response event]. So far so good with some of those, but I’m having trouble figuring out the expression that evaluates the response event. How can I pass that expression as input parameter and how can I execute that input parameter as part of my gateway?

Let’s say that the response event I’m waiting for is “EmailDelivery” and it contains a string property/variable “status = Sent”. Ideally my gateway expression would be “#{status == ‘Sent’}”. However that expression is coming in a variable “responseEvaluation” - how do I execute the value of that variable as an expression and what do I set as the value for that variable?

I’m attaching my “CommandExecutor” model and a “Test” model that is supposed to exercise triggering it.

CommandExecutor.bpmn (7.3 KB)
test.bpmn (2.9 KB)

Thank you,

you can also use a conditional event. cmd_exec.bpmn (8.1 KB)

Hi Martin,
Thanks for the feedback. Indeed a conditional event might be even better. But how do I pass the condition for that event from outside this workflow (as a variable)?

Hi Dimitar,

you command executor can do this via rest-api-call which sets necessary variables. E.g. “executed” and all the variables that necessary for evaluating the expression. The evaluation of the expression can be done with a condition-script-task. Javascript is a good choice and eval() will do all the work as long as all referenced variables are in the context.

A message event instead of the conditional event will be also fine. Then you have to correlate message to the receiving workflow instance and the payload should carry context variables.


1 Like