我正在尝试在工作流完成后在执行过程中设置变量。
在WorkflowStart类中实例化工作流,然后获取值
ProcessInstance pi = runtimeService.startProcessInstanceByKey("workflowName");
System.out.println("runtimeService.getVariables(getId()) "+runtimeService.getVariables(pi.getId())); 上面的命令启动工作流,并执行所有的执行。所以当我写下
public class FlowDelegate implements JavaDelegate {
public void execute(DelegateExecution execution) throws Exception {
execution.setVariable("abc123", "123");
System.out.println("Execution variables - "+execution.getVariables());
}
}上面的行将打印
{
abc123 => Value '123' of type 'PrimitiveValueType[string]'
}因此,在processInstance执行工作流并尝试访问变量之后,我得到了这个堆栈跟踪
并执行
System.out.println("runtimeService.getVariables(getId()) "+runtimeService.getVariables(pi.getId()));
ENGINE-16004 Exception while closing command context: execution e575eb8b-7b84-11e8-a237-54e1ad4a38ce doesn't exist: execution is null
org.camunda.bpm.engine.exception.NullValueException: execution e575eb8b-7b84-11e8-a237-54e1ad4a38ce doesn't exist: execution is null发布于 2018-06-30 20:21:57
一旦进程完成,就不能再通过运行时api访问它。你可以使用。访问这些值的HistoryService#createHistoricVariableInstanceQuery。
更新:同时camunda支持进程启动的返回值,您可以使用RuntimeService.html#createProcessInstanceById,然后使用executeWithVariablesInReturn()来立即获取启动的实例的变量,而不需要对历史变量进行额外的(昂贵的)查询。
https://stackoverflow.com/questions/51099518
复制相似问题