Getting only Form Data fields/variables

Hi,

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.

Thanks in advance.
Anant.

1 Like

@AnantGhatage sounds like you want the Model API: https://docs.camunda.org/manual/7.5/user-guide/model-api/bpmn-model-api/

The fields are not variables until the tasks with those fields are executed.

Hi @AnantGhatage,

do you want to get variables through REST API or inside of JavaDelegate?

Cheers,
Askar

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.

Hi Askar,

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.

Thanks,
Anant

Hi Stephen,

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.

Thanks,
Anant.

@StephenOTT Yes. This way would return server values of form fields and I guess this is the required output. @AnantGhatage, Right?

Hi Hassan,

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.

Thanks,
Anant

@AnantGhatage If the following is what you need to achieve then the way I mentioned should work

The custom UI would be used as a task form & initially would be filled with values of form fields of the current active task

Morning @AnantGhatage,

is that what you are searching for? https://docs.camunda.org/manual/7.5/reference/rest/process-definition/get-form-variables/

this only works for start forms though.

Cheers,
Askar

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.

Both ways are equally hacky as I see it.

Cheers,
Askar

1 Like

@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:

{
  "Forms": [
    {
      "TaskformName": "Form123",
      "fields": [
        "fieldID1",
        "fieldID2",
        "fieldID3"
      ]
    },
    {
      "TaskformName": "Form123",
      "fields": [
        "fieldID1",
        "fieldID2",
        "fieldID3"
      ]
    }
  ]
}

You could obviously structure the json with many different attributes depending on what you need.

Good Morning!

Did you even open a request for this? If so, would anyone have the number?
Otherwise, I can do so if that is the case.

Hug!

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”);

    ((JSONObject) jsonObjectData).put("id",id);
    ((JSONObject) jsonObjectData).put("organizationNameEN", organizationNameEN);
    ;
    JSONArray arr=new JSONArray();
    arr.put(jsonObjectData);
    JSONObject processedData=new JSONObject();
    processedData.put("data",arr );
	execution.setVariable("jsonData",processedData);

Hi, Have you raised this request? If yes Do we have Rest API to get only form field for provided task id?

Hello,

I have the same question w.r.t. REST API.

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 :open_mouth:

    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;
    }

There is no api to get only user task variables. But you can use below code snippet to get form fields

processEngine.getFormService().getTaskFormData(id).getFormFields();