How to create a condition from a list of records to determine the next step

Hello.

Here I have a simple workflow:

  1. Lead generated from a contact form.
  2. Get a list of contacts from the CRM database.
  3. Because there is no API for searching a lead by email field for that CRM. There I tend to do it in n8n by using Filter or If or Switch node, I am not sure if there an ideal action for this step
  4. If a lead is found by matching an email β†’ Update the existing Contact
  5. If a lead is not found by matching an email β†’ Create a New Contact

If I use a Filter node, there will be no action if no lead is found.

If I use an If node, it will only work if a lead is found; otherwise, it will output the remaining leads from the list as false items.

If there was a search lead action for the CRM, the HTTP request would return 200 or 500. This can be used as a conditional action to either create a new contact or update an existing one.

The workaround is to simulate 200 / 500 in n8n. If so, how?
I hope someone has had a similar situation and found a solution they don’t mind sharing.
Thanks.

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

@Blueli , I would implement the workflow differently utilizing Merge nodes instead as depicted below

One of the Merge nodes is looking for a match in email addresses and the other checks if no match found. Thus, the first Merge outputs the form submission data when the email address it is not in CRM and the second one outputs the form submission data when the email address exists in CRM.

Pay attention to how each Merge node is configured to achieve the described behaviour. I also assumed the form field holding the email address is called just email but you can change it to what you actually have.

2 Likes

It is a bit complex, after spent sometime studying it, I managed to resolve it by your solution. Thanks!

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