我創建了一個類UpdateVariableCommand
女巫執行GenericCommand
。
@Override
public Object execute(Context context) {
KieSession ksession = ((KnowledgeCommandContext) context).getKieSession();
WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.getProcessInstance(instanceId);
VariableScopeInstance variableScope = (VariableScopeInstance) processInstance
.getContextInstance(VariableScope.VARIABLE_SCOPE);
variableScope.setVariable(name, value);
return true;
}
我更新變量是這樣的:
/**
* @param processInstanceId
* @param name of variable
* @param value of variable
*/
public void setVariable(Long processInstanceId, String name, Object value) {
UpdateVariableCommand command = new UpdateVariableCommand(processInstanceId, name, value);
ksession.execute(command);
}