Hey, I have a question. I have a multiple-task in Task B, and it requires an input. Unfortunately, in Task A, I need to add multiple items, but Camunda Forms does not support multiple items where you can click on a plus sign to enter multiple items. Is there an alternative solution without creating a UI?
Stringified JSON?
So, I canât enter something like this in the form, for example, being able to enter multiple items in Task A, similar to adding items like pants, a table, etc. Somehow, Iâm getting an error message, but I donât know how to fix it. If I canât add multiple items in the form, how can I solve it alternatively?
The Input Collection
in your screenshot is looking a FEEL list item to iterate over. If the list has 10 elements, it loops 10 times.
I think there are a couple different ways to try to solve you scenario:
- Create your own Tasklist UI that can handle the more complex user interactions you are looking for.
- Have a previous user task where the user enters the number of items they want to add, use that value to fill out the input collection variable, then loop the user task to add an item (see the attached BPMN diagram).
- Include a checkbox on your form asking âWould you like to add another item?â and if it is checked, use a gateway to repeat the previous task:
new-bpmn-diagram.bpmn (5.0 KB)
I liked the second and third points as well because they eliminate the need to implement a UI. In the second point, I understood the process, but I have a few questions. Unfortunately, I couldnât find anything about input iterations in the documentation, so how does the engine know how many iterations to perform based on the numbers in the previous task? Letâs say I select number two and enter two items in the task. In the third task, can everything be displayed at once, or do I need to add another multiple task? I also found the third point good. When I use checkboxes, the values are not overwritten. How can I configure it to display all the items at the end?
Why is there a button in the form for adding an item, but nothing is visible in the Tasklist?
The BPMN term youâre looking for is âmulti-instance markerâ, and you can find the information regarding the iteration here:
It is iterating over a FEEL list, which is essentially an array. However many items are in the list/array is how many times it iterates. If the Input Collection
is set to =[1, 2, 3, 4, 5]
it will iterate 5 times.
As for displaying everything at the end, you would need to make sure you are collecting everything in a way that isnât overwriting previous values.
That was just a dummy model meant to illustrate a concept, not be a fully working solution. It just has a button to quickly complete the form, and I test it in Play Mode.
I understand partially. So, when you write âiteration numberâ as input, the system automatically knows that ânumberâ refers to the iteration because it seems a bit strange to me to understand it that way, as ânumberâ could potentially represent something else in that case. Can you display the items using Camunda without implementing anything? For example, could you take a multiple task where you can only read the value but not change it?
Apologies, I donât understand what youâre saying with âiteration numberâ. What youâve described isnât how Camunda works. Did you read the documentation I linked?
For displaying items, you will be faced a similar scenario: creating your own UI, or using another multi-instance marker to iterate over your collection and display each one at a time. Forms do support read only fields, and there is a text view element available too. This is again a scenario where Camunda isnât strictly designed to do âcustomer userâ operations like what youâre experimenting with. Every one of those users will need have a Camunda account and will need to log in to your Camunda cluster before they can add any products. That isnât a recommended practice. (I think we talked about this same concept regarding a travel agency?)
That was my fault with the iteration number. I understand it now. Thank you very much. I didnât know that I should write the output in the first task. Thank you very much for your help.
Hey, I have implemented the process you provided here, but with my own process. Letâs say I enter â3â in the first task, âget number of items.â In the next task, I can enter something for the first item, but then for the second item, the values from the first item appear again. Finally, when I want to see all the values in the last task, I see the same value twice because I changed it for the second item. Can I adjust this in the process, or is it not possible? I wanted to solve it alternatively without using the UI.
Hi @anon64962691 - that is interesting, that is not the behavior I was expecting to see. The form is, indeed, keeping the previous value entered instead of resetting between iterations. I believe we may have discovered a bug! I will report this to the engineering team.
However, when I run it, I donât get duplicate entries. Are you sure youâre not accidentally entering the same value twice? Hereâs a screenshot of the BPMN model I linked earlier, run in Play Mode. I entered â5â in the first form, then the next form opened five times and I entered a different color in each. You can see that the task is now complete, and the userColors
list variable has the five colors I entered. (Where you see color = null
in the variables list is where I was trying to manually reset the form value, but it wasnât working; hence finding a bug!)
Hey, if you want, I can privately send you my code. Iâve done it almost similarly to how you did it. However, when I input the values and then the loop runs, the values from the last time somehow remain, which I donât want. Also, when I enter different values, I noticed that they are different at the end. For example, after 2 iterations, I input âananasâ as the name and â$5â as the price. In the next iteration, it shows exactly the same. But when I overwrite it with âbirneâ and â$6â, at the end, âbirneâ appears twice.
How do you have your output mapping(s) configured on the user task?
iterations
for x in 1âŚfield_Numberofcandidates return x
Sorry, I meant the output mapping on the âadd itemâ user task, where the user is entering the product and price.
I didn´t put an output there because in your example there was not an output in add item
Oh no, I must have uploaded a previous version. When a form outputs a variable, that variable is available in the global scope of the process. Because it is always returning a variable of the same name it is overwriting the previous value in the scope. You need to set an output mapping to assign the value to a variable of your choice. How you name and configure that variable is dependent on your use case. For this simple example I just append the values to a list.
Iâm now really confused. Hereâs my process:
In the first task, we specify how many items I want to create.
In the second task, each item has three values, and we enter those values.
In the third task, something is corrected.
In the last task, we should see the values and not modify them.
How do I add the values into the output list? In your example, you used âcolours,â but I have three values.
Another question: if I have a regular user task without multiple items, do I still need to set it up with input and output? Iâve never done it that way, and it wasnât done that way in the videos.