My WITH_ITEM still overwrites data instead of adding to list 🧐

Trying to add a new object to this list
image

But my update record formula does not work as expected
SET_KEY(data.updUsersEml, "registeredEmls", WITH_ITEM(pageVars.registeredEmls, data.updUsersEml.registeredEmls[0]))
(I store a list of objects with the 3 properties in the pageVar)
Can you suggest any fix please?

Hi. I am also having problems with the WITH_ITEM formula when trying to add a list of objects in pageVar to a list of object in Firebase. In the end, I started a new collection to solve this.

It is not always wise to create new collections as an easy solution as this practice increases the number of reads… and subsequently your Firebase bill.
Will share any findings as I’m still researching… unless some good soul can help in the meantime.

Don’t use WITH_ITEM() inside the “update record” flow. The update record flow with Firebase works as a “PUT” method that basically overwrites the existing data entry. So instead of using the WITH_ITEM() inside the update record flow I would suggest first do a “set data variable” or “set page variable” or etc with the correct schema and values from the record that you want to update and then assign that already updated record as the record for the update record flow function.

Let me try to help.
Have a page variable set as list of objects like so:

Then:
image
The pageVar WITH_ITEM formula gets the list of objects from the data variable (see “list to add item to”) set as follows:

And that pageVar WITH_ITEM second part of the formula uses the data your user is inputting (for me: date and eml). That data is an object with 2 properties (date and eml). This must match exactly that schema in the data variable which has a list of objects with the same 2 properties.

Once that pageVar is all set, just attach an update record flow function to it and assign the content of the pageVar to its value like so:
The data resource must have the exact same schema: a list of objects with the same 2 properties, same property names.
image

Critical because when you assign the value to the record field, you’ll find the list of objects in question:

…to which you assign the value of the pageVar (which is a list of objects with 2 properties):

Hope this helps.

1 Like

Thanks!!
In the meantime, I had figured out the pageVar challenge by looking at what you had done for adding a new Service to a list of services. The struggle was with Update Record, which ended up being a ridiculously simple set up. It is all about understanding.

1 Like

Thanks for the help! Will try this method in my project! Yup, as you said, it is all about understanding.

1 Like

Thanks for the suggestion! It really is a thing that easily being overlooked. Will keep this in mind when working on my project.