Comparing two tables (data types) and either import thing if doesn't exist OR update existing thing

Hi fellow no-coders,

Working on a SaaS (B2B) App where my users will need to regularly either import new records or update existing records.

Here is what I am trying to build:

  • My target table is called “ObjectsInApp”
  • I have created a temporary table named “ObjectsInApp_Loading” with the very same structure (i.e. both tables have exactly / strictly the same fields)
  • The user uploads a CSV file that is imported in the temporary table “ObjectsInApp_Loading”

So far, so good. This is in place and working.

Now, what I can’t figure out is:

How to compare each row (record / thing) of my target table “ObjectsInApp” to each row of the temporary table “ObjectsInApp_Loading” and do either of the following actions depending on the comparison result :

IF 2 records match THEN the value of the fields from “ObjectsInApp_Loading” will replace existing values in “ObjectsInApp” ELSE (i.e. NO MATCH) create a new record in “ObjectsInApp” using the un-matched record from “ObjectsInApp_Loading”

I’m thinking of some sort of backend recursive API to address this but I don’t know where to start to implement these conditions if at all possible to do this in Bubble…

1 Like

Do the objects have unique identifiers other than what is assigned by Bubble?

You can make a backend workflow , for this example called “edit-objects” , (does not have to be specified as running on a list) that has a key called “objects” and a value of ‘Do a search for all “ObjectsInApp_Loading”’. Make sure to check the box that it is a list.

Action Step 1: Create a “ObjectsInApp” WHEN Do a Search for “ObjectsInApp” (matching identifying fields of “objects” first item) first item IS empty.

Action Step 2: Make Changes to “ObjectInApp” WHEN Do a Search for “ObjectsInApp” (matching identifying fields of “objects” first item) first item IS NOT empty.

(Action Steps 1 and 2 should have identical conditionals except for changing the IS EMPTY to IS NOT EMPTY)

Action Step 3: Schedule API workflow “delete ObjectInApp_Loading” pass in the "objects"first item and set that workflow to take in one item and delete it.

Action Step 4: Schedule API workflow “edit-objects” (recursive) and pass in the same list of objects minus first item. CONDITIONAL only when “objects” minus first item count > 0.

From my experience and searching the forums, this recursive backend workflow method seems to be the best case for working with lists.

Hi William,
Thanks for your guidance.
Your solution corroborates what I started to implement after reading this article.

Except for one thing though >> I didn’t find the need to use the minus first item (in step 4) since I have been deleting the first item from “ObjectsInApp” after processing it (unless I’m missing something or have been (too) lucky with my test file that only had a handfull of records ?). It all works fine now!

Also, for the records and the sake of others who might be having the same issue in the future, I found a promissing plugin to split large files into smaller files in order to cope with the 1000 records limit that Bubble has for csv data import. I haven’t installed or tested it yet but I’ll keep that in my mind for later.

1 Like