Pipedrive node: search an organization, if not found, create one

Hi. I’m trying to use a Pipedrive: Search Organization node to figure out which organizations from a given list are not in the system yet. And if it’s not, I’d like to create one.
My issue is that Pipedrive Search Organization node does not output negative/empty results for those organizations that it didn’t find. So when my next IF node runs, it only sees organization that are in Pipedrive already.
This is driving me crazy

Hey @Artego, my suggestion for your scenario would be to search one org at a time, have the Pipedrive node always output data (like you already do) and then check if a search result is found for each single org.

Like so:

By using batches of 1, you can easily verify whether the search was successful after the Pipedrive node and then proceed accordingly:

A found org will return an item like this:

A non-found org will look like so:

This worked great. Thank you

1 Like

You’re most welcome, glad to hear this helps!

quick question: why can’t I use another similar piece of flow right after this one?

I want to do a similar search but for a person now. The output of Split in batches is 1.

So the easiest solution would probably be to move the “sub” loop into for your person search its own workflow and then call this “child” workflow from your main workflow using the Execute Workflow node.

If you don’t want to use sub workflows you’d need to use the Reset option on your second SplitInBatches node. This can easily get confusing though. Check this thread for an example of how to use the option: Multiple SplitInBatches nodes not working - #6 by jan

Edit: Or lastly, and after re-thinking this it might actually be the “cleanest” solution, merge your multiple executions into a single execution after you have finished searching your organizations and before you start the next loops:

The final loop will then run three times again:

Sorry, I’m not an advanced n8n user, but when I tried adding nodes from your workflow to mine, Merge executions node created 49 of the same outputs. I’m so confused

I changed the node name inside the Merge executions node

let results = [],
  i = 0;

do {
  try {
    results = results.concat($items("Pipedrive12", 0, i));
  } catch (error) {
    return results;  
  }
  i++;
} while(true);

Hey @Artego, is your Pipedrive12 node returning different organizations on each run (you can look at different runs using the “Run” dropdown in the upper left of your screenshot)?

It’s the same organization each run for some reason. If I remove the nodes I’ve added from your example, it works fine

Sorry, I’m wrong. For some reason it just pulls the same organization name each run. I’ll take a closer look. Thank you for your help

1 Like

Hi @Artego, sorry to hear that. Feel free to post a new question on the forum if you need help with sorting out the incoming data here.