Create multiple records based on a list variable

I have a list of objects which I would like to write to a Firestore database.
For context, you can add multiple products to an order and when you submit an order will be created along with the multiple order items. The order items are stored in a page variable which is a list of objects. When I try to map the variable to the create record note I get an error “the type list of objects with 5 variables is not assignable to the type object with 5 properties”, which is understandable. Is there a way to do some sort of loop whereby I can write all the records to the database at once?
An alternative is to create the database records as the items get created which would mean I would need to update the records with the order id once the order has been created, which is not desirable.

one thing to take a look, is in the data variable, if its stated as a list of five objects, because, most likely, its stated as a an object with five properties.

If thats true, in order to change it, you would need to create a list of objects with five properties in your database and then go in the data connector and make a test request and then set the schema, based on the data returned. that way, your data schema, will be the same as the list of objects in your database.

Hi @Dimos_Vamvourellis , thanks for the response! The variable is already set as a list of objects:
image
However please elaborate on making the test request, how do I do that? I don’t see the option under the data connectors.
Regards

actually, im not talking about the page variable, im talking about the data variable.
depending on whether you use firestore or real time database, you should go to your data connection

and follow the steps mentioned above, so the schema from the data coming from your backend, is a list of objects.

I am using Firestore, so I don’t see that option.
Clicking the resource just opens up the schema which I created manually.

oh so youre using the other type of schema ok, so in there you need to do it like this

Hi Niel, did you find any solution? I have the same demand…

I have just stumbled across this. If I understand correctly you need a loop to create individual records in a Firestore collection.

Well there is no built in loop option in the logic flows, but this is the regular way how I (and many other users do it):

Create a page variable “loopIndex” (or any name).

When you want to create the records do the following logic:

set page variable loopIndex value to 0.
Add an IF logic flow with a condition:

pageVars.loopIndex<COUNT(pageVars.listOfObjects)

now add a “Create record” flow function and bind the value of the record to a formula:

pageVars.listOfObjects[pageVars.loopIndex]

To the successful output of the create record connect a new page variable setting flow:
bind the loopIndex value to the formula:

pageVars.loopIndex+1

Connect this flows output to the IF flow mentioned above.
To the false output of the IF flow add any following logic you would have.

This should look something similar to this one: (This is just for demonstration purpose)

1 Like