How to get form field properties using rest api?

I am fetching the start form fields using rest-api, it is fetching all the variables fine, but not fetching the properties of a form field that I have associated with a field while modeling a process in camunda modeler?

The properties I have set



The response I am getting, I also want to get the properties that I have set
q2

1 Like

Hi,
we solved this by creating a TaskListener that reads all these details (label, defaultValue, constraints, etc) from the process execution and creates JSON which is stored as process instance variable with the task id as name and the JSON as value. Then using REST API to get the variable instances we retrieve this JSON and we have all the details.

Best regards,
Paul Palacean

@ppalacean Could you please provide an example or a sample of code?
Thanks in advance

Hi @tarekajaj,
sure.

We create a TaskListener which is called on ‘create’ and ‘complete’ of every user task:

public void notify(DelegateTask delegateTask) {
try {
String taskId = delegateTask.getId();
//get task form data
FormService formService = delegateTask.getProcessEngineServices().getFormService();
TaskFormData taskFormData = formService.getTaskFormData(taskId);
JsonValue formFieldsValue = SpinValues.jsonValue(getFormDataAsJson(taskFormData)).create();
//set the JSON as process variable with name ‘taskId’
delegateTask.setVariable(taskId, formFieldsValue);
log.debug(“Added form variables full details for task {} to process”, taskId);
} catch (IOException e) {
log.error(e.getMessage());
}
}

Then in method getFormDataAsJson(taskFormData) we create a String JSON representation of the form variables using taskFormData.getFormFields() which returns a List then for every FormField we take the attributes we want and add them to the JSON String (formField.getId(), formField.getLabel(), formField.getTypeName(), formField.getValue().getValue(), formField.getValidationConstraints()).

Then call this REST API to get the form fields full details:
http://localhost:8080/engine/resources/variable-instance?deserializeValues=false

with request body:
{
“variableNameLike”: “501bf723-5809-11e8-9d68-309c2313e693”,
“processInstanceIdIn”: [“50176313-5809-11e8-9d68-309c2313e693”]
}

where 501bf723-5809-11e8-9d68-309c2313e693 is your taskID.

Hope it helps.
Paul Palacean

1 Like

Many thanks @ppalacean. this seems to get the job done, and is enough to our use case.
really appreciate your quick reply.

1 Like

Won’t this endpoint suffice?
https://docs.camunda.org/manual/7.13/reference/rest/task/get-form-variables/