I have an use-case where I need to iterate over a list of objects.
Ex: [
{“id”: “id1”, “data”: “data1”},
{“id”: “id2”, “data”: “data2”},
{“id”: “id3”, “data”: “data3”}
]
Now, I have a “for” loop to iterate over the above list and based on a particular condition, I would need to add a new element to this list. Post this, the new element also would need to be considered in the iterations. ie - 4th element also need to go through the logic inside the loop.
Hey @Gopal, welcome to the forums! Inside a for loop you can append elements to the list, but they won’t be iterated over. You would need to use multiple expressions to achieve that, I think. Here’s a really rough test I did in the FEEL Playground (link should contain data+code)
Thanks @nathan.loding for your response. I saw the example you sent over.
My usecase is a bit more complex than this. Let me explain in detail.
Initially, I have a list of objects of size 5. Now I iterate over the full list one by one. When I encounter a specific element matching a condition, I need to add a new element to the list. I also need to update the current element with some property changes. So, basically both add and update needs to be done for the matching elements. And the other caveat is that after the new element is added, the loop needs to start from scratch again - so that if the new element also matches the condition, another copy is created and so on.
Is this possible?
Hi @Gopal - no, this isn’t possible in a single FEEL expression. One primary limitation is that you can’t easily break out of a for loop in FEEL. FEEL expressions are also exactly that - an expression, not a full routine/procedure. You could build something like this user a sequence of script tasks, but I would recommend doing it with a job worker.