Search code examples
camunda

In a Camunda embedded form, how do you specify the bound variable scope?


Within a user task, a segment of the embedded form markup is

...
  <div class="form-group">
    <label for="reference">Reference</label>
    <input class="form-control"
           cam-variable-name="reference"
           cam-variable-type="String"
           name="reference" />
  </div>
  ...

On form entry, the reference field should be empty. On form submission, the associated Camunda process variable is populated with the reference text as a single String as expected.

Reading the Camunda manual, forums etc, there is no setting to specify the bound variable scope,

For this form field, I wish to use local variables (task scoped), not process instance scoped variables.

If process variables are used, if there is a following user task with a form using the same variable-name, that form field is populated with the previously entered value.

I understand that variables can be programmically reset and that I can use a different variable name but use of a local variable would avoid this.

Also, use of process variables results in an excessive number of variables as seen in

cockpit > running process instances > [process-name] > [instance GUID] > variables

Generally, unless the value is to be used later, form based variables have only relevance during form set-up and action processing.


Solution

  • To set local variables in user forms, the easiest way is to define them in a task-listener creating the task. Then you can reference the variables with cam-variable-name in the form.

    Have a look at this post for further details: https://forum.camunda.org/t/variables-in-parallel-process/1476/3