# 参与者从子表格属性中获取(初稿)
# 1.场景介绍
以"第一个表单"及如下报销审批流程为例,讲解1:n数据模型下,如何将“物料”子表格中的所有部门作为“项目经理审批”环节的参与者。
# 2.效果展示
发起报销填报,流程流转到项目经理审批环节时参与者为子表单中"部门"的所有数据。
# 3.实现思路
通过1:n数据模型关系,生成主子表单,在逻辑流中循环遍历获取全部相关数据,实现将子表格中部门属性的所有数据作为后续活动参与者。
# 4.操作步骤
# 4.1 设置流程表单及参与者
- 创建流程,绑定表单,报销填报环节参与者选择流程启动者,项目经理审批环节需要通过逻辑流实现自定义业务参与者规则。
# 4.2 开发逻辑流获取自定义参与者
流程事件-新建服务,拖入脚本图元,双击打开脚本图元,写Groovy脚本实现自定义参与者获取。
import com.eos.workflow.omservice.WFParticipant
List<WFParticipant> empParticipants = new ArrayList<>()
//定义变量获取相关数据中子表格的数据
def orderMaterials = context.relativeData.__bfp_entity.orderMaterials
//循环遍历后将子表格中部门的所有数据加到集合中输出
for(int i=0;i<orderMaterials.length;i++){
def orderMaterial = orderMaterials[i];
//(其中orderMaterial.name取组织机构id时,参与者角色为org,同理为员工、角色时,参与者角色为emp、role
WFParticipant participant= new WFParticipant(orderMaterial.approvalDepartment,null,"org")
empParticipants.add(participant)
}
context.out = empParticipants.toArray(new WFParticipant[empParticipants.size()])