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?
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.
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()).