Search code examples
javaworkflowbpmnbusiness-process-managementcamunda

set / get input / output parameters of a Camunda user task using Java API


I have simple workflow:

[start_workflow] -> [user_task] -> 
-> [exclusive_gateway] -> (two routes see below) -> [end_workflow]

The [exclusive_gateway] has two outgoing routes:

1.) ${if user_task output paramterer == null} -> [NULL_service_task] -> [end_workflow]

2.) ${if user_task output paramterer != null} -> [NOT_null_service_task] -> [end_workflow]

In Camunda Modeler, I've added an output parameter (named out) to the [user_task].

Q: How do I set thet output parameter through Java API before completing the task via:

taskService.complete(taskId);

On the [exclusive_gateway] arrows, I've set this:

Condition type = expression
Expression = ${out != null}

But there's more:

If I delete the output parameter of the [user_task] and set a runtimeService variable before completing the task:

runtimeService.setVariable(processInstanceId, "out", name);

The [exclusive_gateway] does handle the parameter, and routes the flow as expected. Without deleting the output parameter of the [user_task] it seems like: 1. it is never set (so == null) 2. this null value overwrites the value set by

runtimeService.setVariable(processInstanceId, "out", name);

So can I set a task's output parameter via Java API or I can only use process variables?


Solution

  • I guess you are looking for

    taskService.complete(<taskId>, Variables.putValue("out", <name>);
    

    the communication between task and gateway (forwarding of the value) happens through setting the process-variable "out" on complete.

    for more info, check the javadoc.