How to identify which trigger started workflow?

I am using 2 triggers in my workflow n8n form trigger and a webhook or scheduled trigger. The problem is whenever I initiate form trigger, workflow also activates webhook (with no data) or scheduled event trigger. Next node is a Switch node in which I want to write rules based on the triggering node, I tried {{ $prevNode.name }} but it is giving me name of the other trigger which I didnt initialise.

You can see in the attached picture that both the triggers are activated.

This is the Switch node where I am trying to sanitise data from either node and wrirte rules accordingly.

Please help, i dont want to create a saperate workflow for each trigger because of maintenance and modularity.

  • **n8n version: ** 1.29.1
  • Running n8n via (Docker, npm, n8n cloud, desktop app): n8n Cloud

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:

Hey @Takshak,

I would probably use an Edit Fields node to normalise the Form Trigger data so it matches what the webhook sends then use a noop to give a common reference if you need to refer back so an example of this could be like the below where we take the form and rename the fields to name and transaction and for transaction we use the first character either a B or an S.

Using CURL if we send a body containing a name and a transaction when the data comes through the Data noop node it will be the same so now in the workflow you can use {{ $('Data').first().json.transaction }} or {{ $('Data').first().json.name }} and it won’t matter which trigger started it the data will be the same.

Hopefully this helps.

2 Likes

Hi Jon,

First of all, thank you so much for your time and inputs.

The solution you are suggesting sounds more like a workaround to me. I will give it a try but dosent look right to me. My requirement is pretty simple, I want to identy which trigger started the workflow?

Is it not possible to identify that? We are officially supporting myultiple triggers per form and I am having hard time digesting this that there is no other way except merging and sanitising the data. Plus the another concern seems to be a bug where 1 trigger got fired but we can see green line flowing from both the triggers. Please clarify.

Regards,
Vishnu

Hey @Takshak,

As each trigger should only run once you could use $("<node-name>").isExecuted to find out if a node has been run which should work for a trigger node but it will lead to a more complex workflow than the example approach.

I would always recommend sanitising the data as well so that you have a consistent reference point this will also ensure you have the data you are expecting and it will make it easier to maintain.

With the screenshot you posted I was not able to reproduce that but with the way n8n works a workflow can (or should) only be triggered by one trigger at a time. So you can have multiple in there but only the one will start it.

1 Like

That is not working as both the triggers are getting executed i.e. form one and webhook one (without calling). Even after sanitising the data, the webhook one is getting triggered automatically with null data, i have tried this with multiple times and combinations in testing mode. Seems like a bug to me.

Can you give me an exapmple work flow with twi triggers 1 webhook and 1 form or on button click. and when form is submitted there is no feed from webhook node?

Hey @Takshak,

The worklfow I provided alread does exactly that looking at the workflow exection below.

Oddly even if I add the snippet you previously provided I do not get the issue with both executing as a workflow should only be triggered by one trigger at a time.

When you did your test was it a manual exectution or a production one?

Hi Jon,

Apologies for late response. It was a manual test execution. How can I migrate to Prod if test is not working correctly?

Regards,
Vishnu

Hey @Takshak,

I have just done the same test with a manual execution and it appears to be ok as well. Have you tried running it in prod to see what happens?

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