How to only update if date field of DB is less than date field of external API

Application ID 4A47197B-AE30-FA84-FF56-0071F4010900

table:parents
API service: getParents>getParents

Expected Behavior

I am pulling in an array of objects from an external API that contains a date_updated, an id and various properties:

I have items in my database that contain the same id.

I want to update my database from the external API only if the date_updated field in the DB is less than the date_updated field in the external API.

Here’s what I have so far:

I am getting a strange “Unexpected Identifier” error linked to the Map Items or Load Table objects blocks, I am not sure.

I am also unable to clarify the logic I need to:

  1. Filter out the objects that need updating
  2. Create a list of the external API data that I can then use with a bulk update block. I somehow need to combine the objectids from the database with the external API data and I don’t know how to do that.

Any pointers in the right direction would be much appreciated!

Hello @Andreas_Marinopoulos,

please provide your application id, and what should we do in your app to reproduce the issue?

By using the above API service you can see what I have so far.

If you simply invoke the api, you will see

Hello @Andreas_Marinopoulos, can you update info about your problem?
Because when I invoke your API all work without errors.

Regards, Dima

Application ID 4A47197B-AE30-FA84-FF56-0071F4010900

table:
simpleListOrder

API service: simpleTest > updateSimpleTable2

Expected Behavior

  1. Create a variable externalApiList containing a simple array of 2 objects with properties = name, order, updated. This will supposedly come from an External API
[
    {
        "name": "Andreas",
        "updated": "1609246088000",
        "order": "59"
    },
    {
        "name": "Andreas",
        "updated": "1609246088000",
        "order": "66"
    }
]
  1. Create a variable named dbList containing a list of objects from the database that corresponds to those order numbers.

  2. Create a variable updateList that contains the objects in the external Api list with “updated” property which is larger or equal to the “updated” property in the dbList object, but also includes the objectId from the corresponding dbList item

[
    {
        "name": "Andreas",
        "updated": "1609246088000",
        "objectId": "371D1260-CE43-428E-8110-F83DFD142B5F"
        "order": "66"
    }
]

The array should not include the object with “order”: “59” since the updated field of the object in the database is larger than the updated field of the object from the external API.

  1. I want to update the database with the objects in the updateList variable.

Actual Behavior
Here is what I have so far:

[
null,
{
“name”: “Andreas”,
“objectId”: “371D1260-CE43-428E-8110-F83DFD142B5F”,
“order”: “66”
}
]

Is there a more elegant solution as I feel I am taking the long way around to " only update if date field of DB is less than date field of external API"?

For updating, you must use this block
image
The object must have an objectId property of the item that needs to update.

If you found an item that must be updated, you save him to a variable, use Set property to this object with a new value of the order, and save to DB

About your logic, I think dbList not needed if you no need return this list from this API, you just iterate over the External API list, find a needed object in DB and update him.

Regards, Dima

Thanks, it worked, here is the final logic: