How to create or assign values to variables so that a decision will be taken based in this variable using java API

How to create or assign values to variables so that a decision will be taken based in this variable.

This is my BPMN

where the decision is taken at the EXOR gate, based in the variable isHoliday in the non-default sequence flow.

Capture1

Is there anyway to assign this value in one of the user tasks, i cannot use delegate/listener class. this should be done somehow using the java API.

@Ranjith_Kannan are you building a “page flow” type of scenario where each user task is a step in a multi-step form?


When you submit your user tasks, you can submit a process variable (in your context “isHoliday”), which you can then use in your gateway logic.

1 Like

Hi Stephen

I do this to update the variables.

private void setTaskVariables(String taskId, JsonElement contextValue, TaskService ts)
{
Map<String, String> contextVariablesMap = new HashMap<String, String>();
for (JsonElement array : contextValue.getAsJsonArray())
{
contextVariablesMap.put(array.getAsJsonObject().get(“key”).toString(), array.getAsJsonObject().get(“value”).toString());
}
ts.setVariables(taskId, contextVariablesMap);
}

As suggested by you i actually executed this step before i save and complete the task using the task service api.

But even after this my process engine throws
Exception while closing command context: Unknown property used in expression ${isHoliday}

@Ranjith_Kannan you can save a step by applying the variables at the complete step: look at: https://docs.camunda.org/javadoc/camunda-bpm-platform/7.7/org/camunda/bpm/engine/TaskService.html#complete(java.lang.String,%20java.util.Map)

put a AsyncAfter on the user task, and after completing the user task go to cockpit and look at the variables. Do you see the creation of the isHoliday? if so, what is the value and type?

Hi Stephen

I tried what you have suggested

TaskService ts = camundaEngine.getProcessEngine().getTaskService();
Map<String, Object> map= createMap(currentTaskId, contextValue);
saveTask(getTask(processInstanceId));
ts.complete(currentTaskId, map);

But even after doing this i get this error

rg.camunda.commons.camunda-commons-logging - 1.3.0 | ENGINE-16004 Exception while closing command context: Unknown property used in expression: ${isHoliday}. Cause: Cannot resolve identifier ‘isHoliday’
org.camunda.bpm.engine.ProcessEngineException: Unknown property used in expression: ${isHoliday}. Cause: Cannot resolve identifier ‘isHoliday’

The variable is fed to the process engine from a json and then converted to HashMap as key value pairs

“context”: [{
“key”: “isHoliday”,
“value”: “true”
}
]

@Ranjith_Kannan

put a AsyncAfter on the user task, and after completing the user task go to cockpit and look at the variables. Do you see the creation of the isHoliday? if so, what is the value and type?

Can you provide a scvreenshot of cockpit with the variable showing