当前位置:网站首页>How camunda uses script script nodes

How camunda uses script script nodes

2022-06-13 11:37:00 I'm not a fat tiger

stay Camunda in , The script task is an automatic activity , When the process executes a script task , Related scripts are automatically executed .camunda Support is mostly compatible JSR-223 Script engine implementation , such as Groovy, JavaScript, JRuby and Jython.

This paper focuses on the description based on JavaScript Script engine configuration for Camunda Script Services , Complete script based automatic calculation , And return the calculation result to the process variable .

One 、 Design flow chart

edit

The following are the key configuration items of the script node :

edit

 

The settings of the return value of the script calculation result are 2 Ways of planting :

One is to pass. result Variable Property settings . By specifying the process variable name as the... Defined by the script task camunda:resultVariable The text value of the property , You can assign the return value of a script task to a pre-existing process variable or a new process variable . Any existing value of a specific process variable will be overwritten by the result value of the script execution . When no result variable name is specified , Script result values will be ignored .

Two is through execution.setVariable(" Variable name "," A variable's value "); How to set , You can set multiple variables in a script , More flexible .

The following is complete BPMN Model file :

<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0ppniex" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.8.1" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.15.0">
  <bpmn:process id="Process_0a6gw7u" name=" Loan application process Script" isExecutable="true">
    <bpmn:startEvent id="StartEvent_1">
      <bpmn:outgoing>Flow_0kzdck2</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:sequenceFlow id="Flow_0kzdck2" sourceRef="StartEvent_1" targetRef="Activity_1l6o8wm" />
    <bpmn:scriptTask id="Activity_1l6o8wm" name=" Calculate loan limit " scriptFormat="JavaScript">
      <bpmn:incoming>Flow_0kzdck2</bpmn:incoming>
      <bpmn:outgoing>Flow_0h8bikl</bpmn:outgoing>
      <bpmn:script>var yearWages = execution.getVariable("yearWages");
var houseAssets = execution.getVariable("houseAssets");
execution.setVariable("loanLimit", (yearWages+houseAssets)*0.8);</bpmn:script>
    </bpmn:scriptTask>
    <bpmn:sequenceFlow id="Flow_0h8bikl" sourceRef="Activity_1l6o8wm" targetRef="Activity_1wjgiji" />
    <bpmn:userTask id="Activity_1wjgiji" name=" Confirm the loan amount " camunda:assignee="demo">
      <bpmn:incoming>Flow_0h8bikl</bpmn:incoming>
      <bpmn:outgoing>Flow_03h3srs</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:sequenceFlow id="Flow_03h3srs" sourceRef="Activity_1wjgiji" targetRef="Event_0myx83u" />
    <bpmn:endEvent id="Event_0myx83u">
      <bpmn:incoming>Flow_03h3srs</bpmn:incoming>
    </bpmn:endEvent>
  </bpmn:process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0a6gw7u">
      <bpmndi:BPMNEdge id="Flow_03h3srs_di" bpmnElement="Flow_03h3srs">
        <di:waypoint x="600" y="117" />
        <di:waypoint x="692" y="117" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_0h8bikl_di" bpmnElement="Flow_0h8bikl">
        <di:waypoint x="390" y="117" />
        <di:waypoint x="500" y="117" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_0kzdck2_di" bpmnElement="Flow_0kzdck2">
        <di:waypoint x="215" y="117" />
        <di:waypoint x="290" y="117" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
        <dc:Bounds x="179" y="99" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_0myx83u_di" bpmnElement="Event_0myx83u">
        <dc:Bounds x="692" y="99" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_187in45_di" bpmnElement="Activity_1wjgiji">
        <dc:Bounds x="500" y="77" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_0w973ww_di" bpmnElement="Activity_1l6o8wm">
        <dc:Bounds x="290" y="77" width="100" height="80" />
      </bpmndi:BPMNShape>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>

Two 、 Initiate process testing

Sign in :http://localhost:8080/camunda/app/admin/default/#/login

1、 Initiate process , Enter process variables , The following script node calculation requires these two process variables

edit

 

2、 After submitting the process , View flowchart ,Script The script node has been successfully executed

edit

 

3、 View the process variables in the form ,Script The return value calculated by the script node has been written successfully .

edit

 

More reference :

https://docs.camunda.org/manual/7.15/reference/bpmn20/tasks/script-task/

https://github.com/camunda/camunda-bpm-examples/tree/7.15/scripttask

原网站

版权声明
本文为[I'm not a fat tiger]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/164/202206131123063890.html