flowable多实例任务的一个Demo:
流程描述: 由用户输入收件人列表(多个用;
分隔), 邮件内容等, 然后提交任务, 就可以给多个人发送邮件.
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:flowable="http://flowable.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.flowable.org/processdef">
<process id="test_mail_assignee" name="test_mail_assignee" isExecutable="true">
<documentation>测试发送邮件, 手动指定候选人documentation>
<startEvent id="startEvent1" flowable:formFieldValidation="true">startEvent>
<userTask id="sid-62033516-24F1-4E4E-BF24-4658BC754590" name="填写发邮件表单" flowable:candidateUsers="${var_candidate_users}" flowable:formKey="mail_form" flowable:formFieldValidation="true">userTask>
<sequenceFlow id="sid-4BB20B0C-F7CA-4DE8-9DBC-CDAF6B344CE0" sourceRef="startEvent1" targetRef="sid-62033516-24F1-4E4E-BF24-4658BC754590">sequenceFlow>
<serviceTask id="sid-2183A3C0-3CB8-44A4-AC7A-01588667E2C6" name="send mail to multi people" flowable:type="mail">
<extensionElements>
<flowable:field name="to">
<flowable:expression>flowable:expression>
flowable:field>
<flowable:field name="from">
<flowable:string>
flowable:expression>
flowable:field>
<flowable:field name="text">
<flowable:expression>flowable:expression>
flowable:field>
extensionElements>
<multiInstanceLoopCharacteristics isSequential="true" flowable:collection="toList" flowable:elementVariable="to2">multiInstanceLoopCharacteristics>
serviceTask>
<endEvent id="sid-FEE51C53-D5F5-484A-9FEC-9CFA8AB83487">endEvent>
<sequenceFlow id="sid-08691188-CAA4-4638-9CCD-9E0163E5EBBC" sourceRef="sid-2183A3C0-3CB8-44A4-AC7A-01588667E2C6" targetRef="sid-FEE51C53-D5F5-484A-9FEC-9CFA8AB83487">sequenceFlow>
<scriptTask id="sid-26DCE8D1-4387-4134-B265-0391641426EB" name="split收件人" flowable:async="true" flowable:exclusive="false" scriptFormat="groovy" flowable:autoStoreVariables="false">
<script><![CDATA[def m = to.tokenize(';');
execution.setVariable("toList", m);]]>script>
scriptTask>
<sequenceFlow id="sid-5B283531-0C02-4661-9F53-4AC60EED90D4" sourceRef="sid-26DCE8D1-4387-4134-B265-0391641426EB" targetRef="sid-2183A3C0-3CB8-44A4-AC7A-01588667E2C6">sequenceFlow>
<sequenceFlow id="sid-42232B5F-E183-41F1-BF67-45D958706435" sourceRef="sid-62033516-24F1-4E4E-BF24-4658BC754590" targetRef="sid-26DCE8D1-4387-4134-B265-0391641426EB">sequenceFlow>
process>
definitions>
邮件相关变量输入由表单完成(flowable:formKey="mail_form"
), 其中的表单元素id
就是以后的变量名(subject
, to
等).
{
"id": "492d9eaa-8f7a-11ea-a32a-a64a22da418e",
"name": "发邮件表单",
"key": "mail_form",
"description": "mail_form",
"editorJson": {
"name": "发邮件表单",
"key": "mail_form",
"version": 0,
"fields": [
{
"fieldType": "FormField",
"id": "subject",
"name": "邮件主题",
"type": "text",
"value": null,
"required": true,
"readOnly": false,
"overrideId": true,
"placeholder": null,
"layout": null
},
{
"fieldType": "FormField",
"id": "to",
"name": "收件人",
"type": "text",
"value": null,
"required": true,
"readOnly": false,
"overrideId": true,
"placeholder": "收件人(多个用;分隔)",
"layout": null
},
{
"fieldType": "FormField",
"id": "content",
"name": "邮件内容",
"type": "multi-line-text",
"value": null,
"required": true,
"readOnly": false,
"overrideId": true,
"placeholder": null,
"layout": null
}
],
"outcomes": []
}
}
收件人列表由用户输入(变量to
), 然后由groovy脚本切割为List, 并设置为变量toList
def m = to.tokenize(';');
execution.setVariable("toList", m);
所以在"发送邮件"那一步可以设置Collection
为toList
, 然后设置Element Variable
为to2
(不和to
重复就行).
完.