How can i get only the fields/variables marked as Form Data in a form using REST API. /task/{id}/form-variables REST API returns all the variables that are defined in the process instance.
Is there anyway i can get only the variables marked in Form Data as Form Fields? Something that /task/{id}/rendered-form does but i dont need the whole html form, just the variables marked in that particular form.
Hi Anant Ghatage,
One way is to name your form fields with a common prefix for example âff_â then you can query them using âGet Variable Instances (POST)â https://docs.camunda.org/manual/7.5/reference/rest/variable-instance/post-query/
In the request body set variableNameLike to âff_%â to get only form fields and dont forget to set other concerned properties in the request body
@hassang, in that scenario you would only be able to do that for active or completed processes instances where the form has been submitted. Correct? For any forms you have not submitted yet, the variables would not be available in the query.
I need the variables thru REST API. I am currently using the /task/{id}/form-variables REST API to get the form variables, but its returning all the variables not only the ones marked as form field in form data.
I am looking for something that is similar to the /task/{id}/rendered-form REST API which only returns the form fields which are marked as form data for a particular form task.
We have a custom UI for the form task and we want to use this information to show the fields of that form.
I need the form field values for an active form which is yet to be complete/submitted. As we have a custom UI we use these fields to display them to the user.
as far as I can see what @hassang is suggesting, will solve your problem in the fastest way, otherwise you can create feature request.
Or you can set variables to local scope with empty values in task start listener for instance and then just access local variables of the task using REST. In listener then, you can work with org.camunda.bpm.engine.FormService directly.
@AnantGhatage, when are you calling the Rest API? While the process is active? or before the process instance starts?
If it is after the process starts, you could have a execution listener that runs at process start that uses the Model API to get all of the form field ID/variables names from your user tasks, and put these in a JSON object. You could then use the regular get Variable api call to get the JSON object with some structure similar to:
Hi @aakhmerov i have the same problem how should i get this data inside java Delegate i have tried this code but it wasnât helpful:
Object jsonObjectData = new JSONObject();
Long id=(Long) execution.getVariable(âidâ);
String organizationNameEN=(String) execution.getVariable(âorganizationNameENâ);
Path task/{task-id}/form-variables returns all the variables, the oneâs which have been filled before in previous tasks with their values
How to fetch only those variables, which are required to be filled for the current task?
Possible Hack:
Get task/{task-id}/form-variables and then check the variables which are null. They have been initiated but not filled by user.
This will hold true only if all the form-variables of the previous task had some user input. Even if user left a field blank, it is not null at least in string.
I discovered this: If a Long field is left blank, it disappears from form-variables or process-instance variables. The issue with this, that we lose awareness as a system and behaviour of the API is breaking.
This was my approach to get just the form data for custom UI.
Kind of disappointing this isnât exposed via REST api. Iâm scared to find out how many service calls are not available in stock REST api
private final SpringProcessEngineServicesConfiguration config;
@GetMapping("/tasks/{taskId}/formData")
Map getTaskFormData(@PathVariable("taskId") String taskId) {
Map result = null;
var formData = config.getFormService().getTaskFormData(taskId);
if (formData != null) {
result = new HashMap();
result.put("deploymentId", formData.getDeploymentId());
result.put("formKey", formData.getFormKey());
result.put("formFields", formData.getFormFields());
}
return result;
}