在camunda中完成工作流程执行后,如何获取变量?

时间:2018-06-29 10:18:30

标签: workflow camunda camunda-modeler

我正在尝试在工作流执行完成后设置变量。

在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

1 个答案:

答案 0 :(得分:0)

该过程完成后,就可以通过运行时api对其进行更长时间的访问。 您可以使用。 HistoryService#createHistoricVariableInstanceQuery以访问值