Alternative multiple items in a task

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 @FC_Catalonia - 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.