How do you guys deal with this situation?

How do you guys deal with this situation?

There is no ability to “match” one list to another… which causes the 2 lists to be “out of alignment”.

@RedPacketSec I had a similar situation with one of the flows I was working on.
I added a unique identifier number/name for each record so no matter how the data was manipulated I can merge and match the data based on the unique identifier that was never changed.

in your case, it seems like you are trying to remove an item you already have before you merge the items together…

You might want to just add a data point that says the image already exists then filter it out after merge…
Anyway, in my eyes based on the photo, you provided there are a bunch of ways to solve this.

Would be happy to help in any way I can.

2 Likes

Hi @RedPacketSec, my suggestion would be to use a common key for both branches. If you don’t have one yet, you could add it using a Set node before the Item Lists2 node from your screenshot. An expression like {{(+new Date).toString(36).slice(-5) + Math.random().toString(36).substr(2, 5)}} could add a random key to each item.

Using this key, you could then use the Merge By Key operation of the Merge node.

Example Workflow

Edit: Nevermind, @David_Go beat me to it :smiley:

2 Likes

interesting i will have a play around and see how that works out, thanks for the ideas.

1 Like

I am just trying to give back when I can :slight_smile:
Still, I really like that your expiration came with an example workflow! I know all the examples people like you share really help me and others get a much better idea of how to get things done in the most optimal way.

Like the this " expression like {{(+new Date).toString(36).slice(-5) + Math.random().toString(36).substr(2, 5)}} could add a random key to each item." That is a really good idea I think I might use in my flow since I have been doing this in a less automated fashion … so I guess you now helped me save some time and effort on my own flows :slight_smile:

@MutedJam Thanks again, for opening my mind to how n8n can help me save time and make a reliable scalable process.

3 Likes

fyi, just to be complete. There is also the variable $position which returns the index of the item, which could also be used here.

3 Likes

interesting thanks.

I’m going to try first with the unique id, as I think that might work well

This would result in the simplest way to reference data from a previous nodes. I’m pretty sure @RicardoE105 had a great example, but I can’t seem to dig it out. Anyway here’s an example flow simply using the $position variable:

Workflow JSON
3 Likes

well with a few extra merges here and there I think that using the unique code generator and the field merge has worked.

3 Likes