How to create a new thing for each thing of a list

Hello everyone.

Guys I have a table called Ordered_wrapper in which has a field called orders that receives a list of order_product.

Basically, once the Ordered_wrapper is created with the list of Order_products I need to create a thing Chat for each order_products of this ordered_wrapper.

Here is an example of each one Chat thing is created for each order_product thing from ordered_wrapper thing:

Telling that Chat has a relationship with order_product:

Chat table:

  • order_product → Order_product
  • messages → List of messages…

Here is where I am having a hard time to bring the solution of creating a new chat for each order_product:

1 Like

Hi Elias,

The easiest way to create a list of things is to create a recursive loop from the backend workflow. You’ll find a lot of posts about this method in the forum.

However in your case, I don’t think this is necessary.
Indeed, a chat needs messages and a data type (or more) to know they belong a specific thread.

Basic reminder of database structuring: When you have a long list of records it is better to store the reference data type in the record, rather than storing the list of records in the reference element. Not to mention security, this also allows you to have more control over the display (sort by date, etc…)

So in your case you could create a data type message in which you store Ordered_wrapper and order_product.

To get back your chat thread, you just have to do a Do search for message with Ordered_wrapper and order_product as constraints.

PS: Consider adding a field to manage privacy rules.
Check this documentation to know more about messaging app datastructure.

Based on the recursive looping. How can I make the number of new chats that need to be created based on the number of order_products?

Let say, if I have 3 order_products, I just need to create 3 Chats and connect each of them with each of the Order_products. Should I add the Order_products as the number of iterations?

1 Like

I will share here what I have done to find the solution.

Following @devease advise and this post from

What I did:

FIRST STEP: I created an API workflow to create new-chats, where I passed the “order_products” param as list of Order_product thing and the “iteration” param as number.

SECOND STEP: I scheduled this API workflow I have created before, when I click the confirm button, where the Ordered_wrapper* thing with the list of Order_product things will be created, passing the list of the Order_product list to the backend through the API backend workflow.

See the order_product param receiving a list of order_products thing as “ordedrs” (different name):

THIRD STEP: I scheduled the API workflow within itself (that is why the name recursive) to iterate and create the loop passing the params again. Remembering that within the condition I make an EXIT expression to stop the iteration when the iteration param be smaller than the number of order_products.

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.