在jbpm4.3中,一般在启动流程的时候就把所有变量设置好了,也就决定了流程的最终走向。这样的流程还不够灵活,其实jbpm4.3已经考虑到这个问题,所以提供了变量值改变的接口。
启动流程时设置的变量,其实是抽象了不同的流程。使得所有的符合这个流程的业务都可以流转。
在流程启动后设置变量,其实是对该流程的抽象。使得该流程更加灵活。
上代码。
if(taskName.equals("行政确认")){
Map<String, Object> variable = new HashMap<String, Object>();// 流程中要用到的变量信息
variable.put("hrPass", "已批");
jbpmTemplate.setFlowVariables(beout.getBeoutId().toString(),variable,taskName);
if(beout.getActualTime().after(beout.getEndTime())){
variable.put("timeOut", "超时");
jbpmTemplate.setFlowVariables(beout.getBeoutId().toString(),variable,taskName);
}
}
jbpmTemplate.completeTask(taskId, approvalResult);
那么在模版中的函数是这样的
public void setFlowVariables(String key, Map<String, Object> variable,String name){
Execution execution = getProcessInstance(key).findActiveExecutionIn(name);
executionService.setVariables(execution.getId(), variable);
Execution execution = getProcessInstance(key).findActiveExecutionIn(name);
executionService.setVariables(execution.getId(), variable);
}
这样就可以根据流程的走向来动态指定流程的走向。