如何在 JBPM 中设置/修改正在运行的流程实例的流程实例变量?是否有任何预定义的命令类来设置 process-instance-variables ?
我可以看到一些命令,例如org.drools.command.SetVariableCommandFromLastReturn
&&
org.drools.command.SetVariableCommandFromCommand
我可以使用这些命令吗?如何使用这个命令?
截至目前,我正在使用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;
}
});