Whats the best way of removing results from an array server side

I am returning 100 results from a single call to an API as an Array
I have a database query with a few records of productCode

I would like to only show the API records that do not exist in the Database records, as if they are already in the database, it means that product is already done and no longer requires processing.

What is the best way to arrayRemove from the server side?

I had a similar requirement and ended up writing a formatter, similar to .where(), returning results where a property only existed in another array - in my case I had a previous query and flattened for an ID. You could then use that for a repeat loop.

There are ‘inArray’ and ‘notInArray’ options for the client-side where formatter but not for server-side. Is there a reason for this @patrick?

1 Like

I managed to work around it by passing it back through a repeat and checking each record against the database records, then used a Set Value step to only output in a condition when the record was not equal to the database record.

Unfortunately this caused a new problem of returning an array of 100 objects even though 20 of the objects were now blank.

I made a custom formatter to clean all the empty objects out array1.filter(value => Object.keys(value).length !== 0)
And now I have what I wanted only the remaining 80 records that have never been processed.

Repeats are slow when you have too many records to repeat.
Better to just create a custom formatter to compare the two data set and get desired result.

If you still want to use repeat, you can just use where formatter on final repeat output and use in set value to remove empty items.
If that does not work, create a set value inside repeat which would just have tried it false values. So, outside the repeat you can just do a where formatter to filter based on that variable.

1 Like