Hello, I have a question. Is there a way in Camunda forms to configure fields so that something must definitely be entered in the field, but it can also be optional? My other question is, is there a way to have a counter in the forms, for example, if you have a loop, that indicates how many times the loop has been executed?
If something must definitely be entered into a form field, then that field, by definition, is required. Do you mean that you want to make a field conditionally required?
For the counter, every multi-instance task instance has a special variable named loopCounter
that does exactly this: Multi-instance | Camunda Platform 8 Docs
Hello @anon64962691 ,
Regarding the counter in the form, you can map the process variable to an element in the form. From your example you describe a loop in the process. If you use Multi-instance you can use the loopCounter variable as @nathan.loding noted, if you designed the loop yourself, youâd probably be using a kind of counter variable as well which can be mapped to an element in the form.
I mean exactly that the field is set to ârequiredâ?
I want to design the loop myself but donât know how to do it.
There is a âRequiredâ checkbox in the form designer under the âValidationâ section:
Thank so you much.
So that means I should implement a code?
I donât think I follow. Implement code like in Java/Javascript? The variable and the gateway condition were implemented with FEEL within the Camunda Modeler
I saw the two script tasks and I thought I should implement a code. I do not know how to put the counter Variable in a form
Hi @anon64962691.
So to summarize, since this seems to be a little chaotic.
- You can use the ârequiredâ checkbox in âvalidationâ in the form editor to make a field, well, required.
- You can use âhide ifâ in âconditionsâ in the form editor to hide/show a field based on some input data.
- If you use multi-instance, there is a helper variable called loopCounter which youâll have access to in scope.
- Otherwise, if youâre implementing some other kind of loop via a script, you need to add the variable to the process yourself.
Regarding how to put the variable in a form, this happens automatically. We calculate the variables required in your form from the form schema and pull them in when the form is initialized from the variable scope.
Example full setup:
Form - You have a text field with required set to true and hide-if set to counter > 5
Bpmn - You do some work, whatever your loop looks like, and you put a variable named counter
in the variable scope. You then reference the form in your bpmn after all that work has happened.
If you feel thereâs a form feature missing for your use case, feel free to raise an issue over at GitHub - bpmn-io/form-js: View and visually edit JSON-based forms. and we can investigate it
What I want is to set up a counter that increments by 1 with each loop. I know I need to use a number field, but Iâm not sure how to set it up in the gateways or within the task. Is there any documentation for this
You donât need to use a number field, only if you want it displayed (or edited) within a form. There is no specific documentation for this, but it can be easily accomplished with output mappings and FEEL expressions, both of which are well documented. Have a look at the attached model! (Note: there is still a bug with Play mode where the output mappings arenât working quite right, so deploy this model to test it.)
manual-loop.bpmn (5.2 KB)
I understand, thank you. Do I need to set it up separately in the form, for example, to only display the counter when itâs greater than 10, or do I need to use a FEEL expression to achieve what Iâve written?
Iâm not sure I understand the question. Do you only want to show the field in the form when the value is greater than 10? For this manual loop counter, you donât need to show the value in the form at all, itâs entirely your choice. It works with or without the form.
I want to set it up so that the counter is only displayed in the form when the counter is greater than or equal to 10.
In the form builder you can conditionally hide fields using FEEL expressions. Keep in mind this is a hide condition, not a show condition, so it needs to be the inverse of your logic. (Which I got wrong for the screenshot - it should be =loopCounter < 10
for the logic you described.)
Thank you very much. Iâll try it out right away.