Query Formdata using rest api

Hi, I want to get the formdata of a task or a processDefinition using rest api.
The first approach is that I set the form properties (of a task) one by one, and I can get the formdata using api.
But the second approach is that I associated a task with a reference form, in this way I cannot get formdata using rest api.
So is there something I did wrong? Or currently, if I want to use rest api to query formdata, the only way is setting form properties one by one?

Regards,
Ziwen

Hi Ziwen,

The form data api is there for the form properties approach we have since a long time in Flowable. The new approach is using the form definition JSON you create in the Flowable Modeler and reference from the user task. There is a separate api for using the new form definitions. On the RuntimeService there’s the getStartFormModel method to fetch a start form model and startProcessInstanceWithForm to start a new process instance with the form input. On the TaskService there’s the getTaskFormModel method to fetch a task form and completeTaskWithForm to complete a task with the form input.

Best regards,

Tijs

Thanks for the reply, but I am current using rest api to interact with flowable-task.
The domain is localhost:8080/flowable-task/process-api
So in the docs, there is a GET form/form-data rest api to get form data, but it can only get data if I set form properties one by one in the modeler, but not if I associate a usertask with a customized reference form.

Regards,
Ziwen

Hi Ziwen,

Ok, for the rest api the same difference is true. the form/form-data rest service only provides the form properties defined on a user task. On /flowable-task/form-api/form-repository/form-definitions you can query on form definitions with the key you used when creating the form definition in the Flowable Modeler. And with /flowable-task/form-api//form-repository/deployments/{deploymentId}/resourcedata/{resourceName} you can get the actual form definition JSON.

Best regards,

Tijs

Thank you very much. It works. I wonder if there is any way to get the entire form, like a html component, so its appearance will looks like the same as when I designed it.
I mean that I can put the this form component directly in html, instead of rendering it with all the properties myself.

Regards,
Ziwen

This is my solution to load a Form.
I use the Flowable Rest Api / swagger

public Optional<FormModelResponse> getFormInstanceModelByTaskId(String taskId) {
    Optional<FormDataResponse> formData = getFormsByTaskId(taskId);
    if (formData.isPresent()) {
        try {
            //When a form loads the First time it is not saved as FormInstance during PE. So u have to do it in your own way
            String formInstanceId = createEmptyFormInstanceIfNotExists(formData.get().getFormKey(), taskId);
            FormRequest formRequest = new FormRequest();
            formRequest.setTaskId(taskId);
            formRequest.setFormInstanceId(formInstanceId);
            //Now you can load a the Form Instance because later u need the Version of your Process corresponding Form Deployment
            FormInstanceModelResponse instanceData = flowableServiceFactory.getFormInstanceModelsApi().getFormInstanceModel(formRequest);
            FormDefinitonQueryModel formDefinitionQuery = new FormDefinitonQueryModel();
            formDefinitionQuery.setKey(instanceData.getKey());
            formDefinitionQuery.setVersion(instanceData.getVersion().toString());
            // With the Formdefinition Query you get The Form Definition id in the Correct Version you need that for the Form Definition id
            DataResponseFormDefinitionResponse formdDefResult = flowableServiceFactory.getFormDefinitionsApiExtended().getFormDefenitionByQuery(formDefinitionQuery);
            formRequest.setFormDefinitionId(formdDefResult.getData().get(0).getId());
            //Now your Query is ready to load the Form in the correct Version with your task.
            // That is not funny -> so much requests for a correct loaded Form. I hope there is a better way in future
            FormModelResponse data = flowableServiceFactory.getFormModelsApi().getFormModel(formRequest);
            return Optional.ofNullable(data);
        } catch (ApiException e) {
            e.printStackTrace();
        }
    }
    return Optional.empty();
}