Continue if "no items found" logic

When building one-way synchronization between systems, I often want to do a check for data in the destination and only continue if NO data is found.

I’m trying to use a node to search for existing data with the setting Always Output Data, and then an If node that only continues if it is “false”.

However this doesn’t seem to work when there are multiple entries that do not return values.

In this workflow below, there are 7 items going into the “CWM Get Schedule Entries”, but only 2 come out, even though it is set to Always Output Data.

The problem is the If node is only receiving the items that are not null/blank.

Hi @j0dan, this is unfortunately expected. The Always Output Data option would return a single empty item if otherwise no other items are returned. What you could do in such cases is using the Split in Batches node and split your data into batches of 1, then run the HTTP Request node for every single item individually. This way, the total count wouldn’t change.

If you need a single list of items after your loop check out @BramKn’s iterator node (New community node: Iterator) which should make this really simple (or use the regular Split in Batches node and this Code node if you can’t or don’t want to use community nodes).

1 Like

Hi @j0dan

There is always multiple options. Some of which were mentioned by @MutedJam

Not sure on the usecase exactly but you can also count the items coming out of a node.

So you might be able to simply count the items.

Or if you need to check for the items, another option is to merge the output of the HTTP node with the incoming data to see what data did and did not return data.

Another option might be to set the http node to also give headers and status in the response. This should in theory always give the same nr of items as a response so then you can check them one by one.

As I said, there is a lot of ways of doing things and I am not 100% clear on the use case to determine the best way of doing it. Just wanted to give you some extra ideas. :slight_smile:

1 Like

That one is clever and seems to get me to the right place. Thanks!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.