1

Using Flowable 6.4.0 (also applies to Activiti 6.0.0) I am rendering task form in my application by reading task form properties:

for (FormProperty formProperty : formService.getTaskFormData(taskId).getFormProperties()) {
//... render form field
}

I would like to replace this with Forms that can be designed in form designer and are set on task as formKey (also formReference, seems formReference is web app feature to select form to set formKey and deploy form to app). Problem is I do not see any API method to read form properties based on form key.

Reading answers in this question using formKey is correct way since task form properties are "deprecated", but is there API support for reading form fields for given formKey? Something like formService.getFormData(formKey, taskId).getFormProperties();?

Documentation (Flowable, Activiti) talks only about reading deployed form resource file my-custom-form.xml, does that mean I have to parse form file myself? I also checked Flowable Form Documentation and Sources but I do not see how to read form fields.

Piro
  • 1,367
  • 2
  • 19
  • 40

2 Answers2

3

If you want to use forms designed with the Flowable Form Designer, then there are additional API methods to fetch a start form and task form in Flowable. The getTaskFormModel(String taskId) method in TaskService gives you for example the form definition associated with the Task with that id:

https://github.com/flowable/flowable-engine/blob/master/modules/flowable-engine/src/main/java/org/flowable/engine/TaskService.java#L323

If you look in the implementation of this method you can see that it uses the formKey attribute of the userTask element to lookup the form definition based on key.

To get a start form of a process definition you can use the following code to lookup the formKey attribute of the startEvent element and get the form definition by key from the FormEngine:

https://github.com/flowable/flowable-engine/blob/master/modules/flowable-rest/src/main/java/org/flowable/rest/service/api/repository/ProcessDefinitionResource.java#L145

When you retrieved the FormInfo class from the getTaskFromModel method you can use the getFormModel method to retrieve the FormModel interface to get an instance of the Form model. Because the FormModel is made pluggable to make it easier to define your own Form model structure, you need to cast the FormModel interface to SimpleFormModel. From there you can use the getFormFields method to get to the form fields of the form definition.

  • I looked at `taskService.getTaskFormModel(String, boolean);` it returns `org.flowable.form.api.FormInfo` that has no fields. I can obtain `org.flowable.form.api.FormModel` from it, but that is empty interface. That is why I probably got confused. Looking at `org.flowable.form.model.SimpleFormModel` implementation of `FormModel` it has form fields. So all it takes is to cast `FormModel` to `SimpleFormModel`? You could add this to answer then so it is complete. – Piro Jan 10 '19 at 05:17
  • `that has no fields` I meant no form fields – Piro Jan 10 '19 at 06:08
0

Code that worked for me in a TaskListener (Flowable 6.7.1) based on Tijs Rademakers' answer:

FormInfo taskFormData = Context.getProcessEngineConfiguration().getTaskService().getTaskFormModel(delegateTask.getId());
List<FormField> formFields = ((SimpleFormModel) taskFormData.getFormModel()).getFields();
lights
  • 1,034
  • 1
  • 8
  • 22