如何在 Camunda-BPM 中设置全局流程变量? [英] How to set global process variables in Camunda-BPM?

查看:160
本文介绍了如何在 Camunda-BPM 中设置全局流程变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 bpmn 流程其中我正在使用 2 个服务任务,我正在通过使用执行我的流程processEngine.getRuntimeService().startProcessInstanceByKey("Process_1", variables);其中我的变量如下:

I have a simple bpmn process in which i am using 2 service task,I am executing my process by using processEngine.getRuntimeService().startProcessInstanceByKey("Process_1", variables); where my variables is as follows:

Map variables = new HashMap();
variables.put("a", 2);
variables.put("b", 5);

服务任务 1 实现了一个 Addition java 类,服务任务 2 实现了一个 Multiplication 类.

Service task 1 implements an Addition java class and service task 2 implements a Multiplication class.

现在我想要 3 个变量(常量)c = 5, d = 10, e = 2 以便我可以使用c 用于服务任务 1 这样在 Addition 我可以使用这个变量,同样我想在我的 Multiplication 中使用 dcode> 类,e 应该是全局的,以便我可以在两个类中使用它.

Now I want to have 3 variables (constants) c = 5, d = 10, e = 2 so that I can use c for service task 1 such that in Addition I can use this variable, similarly I want to use d in my Multiplication class, and e should be global so that I can use it in both classes.

有人可以指导我吗?

推荐答案

作为快速修复,您可以将设置服务任务作为流程的第一个任务,该任务预填充您的流程变量.根据您启动流程的方式,您可以:通过 java-object-api

As a quick fix you could include a Setup-Service Task as the first Task of the process which prefills your process-variables. Depending on how you start a process you could either: Set the Variables via the java-object-api

https://docs.camunda.org/manual/7.5/user-guide/process-engine/variables/#java-object-api

或者,如果您使用 REST 调用,则可以在请求正文中提供这些固定值:

or you if you use a REST call you can provide these fixed values within the request body:

https://docs.camunda.org/manual/7.5/reference/rest/process-definition/post-start-process-instance/

另一个简单的解决方案是使用静态值的类或保存所需值的枚举.

Another simple solution would be a class with static values or a enum holding the needed values.

--编辑--

如果您想使用 inputOutput 扩展名,请在您的 bpmn 文件中添加如下内容:

if you want to use the inputOutput extension add something like this to your bpmn file:

<bpmn:process id="Process_1" isExecutable="false">
  <bpmn:extensionElements>
    <camunda:inputOutput>
      <camunda:inputParameter name="c">5</camunda:inputParameter>
      <camunda:inputParameter name="d">10</camunda:inputParameter>
      <camunda:inputParameter name="e">2</camunda:inputParameter>
    </camunda:inputOutput>
  </bpmn:extensionElements>

这不能在camunda建模器的图表视图中完成,只需切换到流程的XML表示并添加extensionElement即可.

this can't be done in the diagram view of the camunda modeler, just switch to the XML representation of the process and add the extensionElement.

这篇关于如何在 Camunda-BPM 中设置全局流程变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆