首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在camunda中完成工作流执行后获取变量?

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

Stack Overflow用户
提问于 2018-06-29 18:18:30
回答 1查看 492关注 0票数 1

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

在WorkflowStart类中实例化工作流,然后获取值

代码语言:javascript
复制
ProcessInstance pi = runtimeService.startProcessInstanceByKey("workflowName");
System.out.println("runtimeService.getVariables(getId()) "+runtimeService.getVariables(pi.getId()));   

上面的命令启动工作流,并执行所有的执行。所以当我写下

代码语言:javascript
复制
 public class FlowDelegate  implements JavaDelegate {
    public void execute(DelegateExecution execution) throws Exception {
        execution.setVariable("abc123", "123");
        System.out.println("Execution variables - "+execution.getVariables());      
 }
}

上面的行将打印

代码语言:javascript
复制
{
  abc123 => Value '123' of type 'PrimitiveValueType[string]'
}

因此,在processInstance执行工作流并尝试访问变量之后,我得到了这个堆栈跟踪

并执行

代码语言:javascript
复制
 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
EN

回答 1

Stack Overflow用户

发布于 2018-06-30 20:21:57

一旦进程完成,就不能再通过运行时api访问它。你可以使用。访问这些值的HistoryService#createHistoricVariableInstanceQuery。

更新:同时camunda支持进程启动的返回值,您可以使用RuntimeService.html#createProcessInstanceById,然后使用executeWithVariablesInReturn()来立即获取启动的实例的变量,而不需要对历史变量进行额外的(昂贵的)查询。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51099518

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档