-
内置表单需要在每个节点中去配置,当如果多个节点使用同一套表单属性就要配置多次比较麻烦,修改的时候也要修改多次,外部表单可以定义一次,然后其它节点都去引用同一个表单属性。
-
外部表单需要定义一个
.form
后缀的文件。 -
外部表单不需要在每个节点去指定From属性,而是在每个节点指定Form Key属性即可。
定义.form
FormLeaveProcess.form
{"key":"FormLeaveProcess","name": "请假流程外部表单","fields": [{"id": "startTime","name": "请假开始时间","type": "date","required": true,"placeholder": "empty"},{"id": "endTime","name": "请假结束时间","type": "date","required": true,"placeholder": "empty"},{"id": "reason","name": "请假原因","type": "string","required": false,"placeholder": "empty"}]
}
配置Form Key
部署流程和部署表单
@Autowired
private RepositoryService repositoryService;@Autowired
private FormRepositoryService formRepositoryService;@Test
void deployFormProcess() {// 1.部署流程Deployment deploy = repositoryService.createDeployment().addClasspathResource("processes/FormLeaveProcess.bpmn20.xml").name("外部表单请假流程").deploy();// 2.部署表单formRepositoryService.createDeployment().addClasspathResource("processes/FormLeaveProcess.form").name("请假流程外部表单").parentDeploymentId(deploy.getId()).deploy();
}
启动流程
@Autowired
private RuntimeService runtimeService;@Test
void startProcess() {String processDefinitionId = "FormLeaveProcess:2:48920686-8145-11ee-b7ee-0a0a3d6982e3";runtimeService.startProcessInstanceWithForm(processDefinitionId, "表单请假流程outcome", null, "huihui的请假流程");
}
完成表单任务
@Test
void completeFormTask() {Map<String, Object> variables = new HashMap<>();variables.put("startTime", "20221111");variables.put("endTime", "20231110");variables.put("reason", "活着不是为了工作,工作是为了活得更有意义");String taskId = "0f273f73-8149-11ee-b15c-0a0a3d6982e3";String formDefinitionId = "652cb868-8145-11ee-a2f0-0a0a3d6982e3";taskService.completeTaskWithForm(taskId, formDefinitionId, "huihui", variables);
}
获取任务对应的表单数据
@Test
void getTaskFormData() {FormInfo taskFormModel = taskService.getTaskFormModel("0f273f73-8149-11ee-b15c-0a0a3d6982e3");System.out.println(taskFormModel.getId() + "-" + taskFormModel.getName() + "-" + taskFormModel.getKey());SimpleFormModel simpleFormModel = (SimpleFormModel)taskFormModel.getFormModel();List<FormField> fields = simpleFormModel.getFields();for (FormField field : fields) {System.out.println(field.getId() + ":" + field.getType() + ":" + field.getName() + ":" + field.getValue());}
}