As of now I am updating the variables like this with GenericCommand
.
kSession.execute(new GenericCommand<Boolean>() {
public Boolean execute(Context context) {
//Get session in the command context
StatefulKnowledgeSession ksession = ((KnowledgeCommandContext) context).getStatefulKnowledgesession();
//Get the process instance
ProcessInstance processInstance = (ProcessInstance) ksession.getProcessInstance(processInstanceId);
//Get variable scoprts
VariableScopeInstance variableScope = (VariableScopeInstance) processInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);
Iterator<String> piStateItr=piStateVariables.keySet().iterator();
//Modify required variables
while(piStateItr.hasNext()){
String variableName=piStateItr.next();
String variableValue=piStateVariables.get(variableName);
logger.debug(">>> Setting State - key "+variableName +" , to "+variableValue );
variableScope.setVariable(variableName, variableValue);
}
return true;
}
});