Get previous node name

Is there a way to get the name of the triggering (or previous) node in a variable somehow ?

For example, I have different cron triggers named differently, triggering the same task. Is it possible within that task to echo the name of the node that triggered the task ?

Sorry, no there is sadly nothing like that right now.

A workaround would be to add a Set-Node after each of the trigger nodes and create a property with the node-name.

Thanks @jan. Maybe that would be good to add it in the future as a few properties of the trigger node or even the previous node in a chain could be interesting to pass around.

How do you set a global property (or at least a property not linked to a specific node)?

Yes, I agree. Thought about that already for a while now. Like some kind of metadata. Anyway, first have to think about how to handle that data exactly and what other data to add. But definitely, something that is needed.

Sorry, there are currently also no global properties yet. What exactly do you have planned? Maybe there is a work around.

I’m trying to have for example many different triggers all triggering a common action that can then display the name of the trigger or any other to identify the source of the trigger, instead of having one display action per trigger.

Does something like that work for you:

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "path": "webhook1"
      },
      "name": "Webhook 1",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        250,
        500
      ]
    },
    {
      "parameters": {
        "path": "webhook2"
      },
      "name": "Webhook 2",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        250,
        700
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "startedBy",
              "value": "webhook2"
            }
          ]
        }
      },
      "name": "Set startedBy 1",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        450,
        500
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "startedBy",
              "value": "webhook2"
            }
          ]
        }
      },
      "name": "Set startedBy 2",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        450,
        700
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "number": [
            {
              "name": "number1",
              "value": 1
            },
            {
              "name": "number2",
              "value": 2
            }
          ]
        }
      },
      "name": "DO SOME OTHER STUFF",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        850,
        500
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "startedBy",
              "value": "start"
            }
          ]
        }
      },
      "name": "Set startedBy",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "startedBy",
              "value": "={{$node[\"Main Workflow Start\"].data[\"startedBy\"]}}"
            }
          ]
        }
      },
      "name": "Use startedBy",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        1050,
        500
      ]
    },
    {
      "parameters": {},
      "name": "Main Workflow Start",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        650,
        500
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Set startedBy",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook 1": {
      "main": [
        [
          {
            "node": "Set startedBy 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook 2": {
      "main": [
        [
          {
            "node": "Set startedBy 2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set startedBy 1": {
      "main": [
        [
          {
            "node": "Main Workflow Start",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set startedBy 2": {
      "main": [
        [
          {
            "node": "Main Workflow Start",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "DO SOME OTHER STUFF": {
      "main": [
        [
          {
            "node": "Use startedBy",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set startedBy": {
      "main": [
        [
          {
            "node": "Main Workflow Start",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Main Workflow Start": {
      "main": [
        [
          {
            "node": "DO SOME OTHER STUFF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Trying to trigger the webhook and see if this works for me but I haven’t been able to so far.
Is the webhook URL https://n8n.xxxx.xx/hooks/2/webhook1 for example?

You can get the webhook URL simply from the webhook node itself. Simply open it, click on " Webhook URLs" and there select “Test”. It will then display you the Test-Webhook-URL. If you click on that one, it will automatically copy it for you so that you can, for example, paste it in your browser.

Btw. here are also some tutorial videos which help to get started:
https://n8n.io/tutorials

Thanks @jan. The proposed workflow seem to always return webhook2 for me though.

Found the issue, in your example, both Set after the webhooks set the value to webhook2. Your example works and I can use it for my case, thank you :slight_smile:

Ah yes, just also saw my mistake.

Great to hear that this works for you!

Always happy to help!

{
  "name": "test",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "path": "webhook1",
        "responseCode": 403
      },
      "name": "Webhook 1",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        650,
        720
      ]
    },
    {
      "parameters": {
        "path": "webhook2"
      },
      "name": "Webhook 2",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        650,
        920
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "startedBy",
              "value": "webhook1"
            }
          ]
        }
      },
      "name": "Set startedBy 1",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        860,
        720
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "startedBy",
              "value": "webhook2"
            }
          ]
        }
      },
      "name": "Set startedBy 2",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        860,
        920
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "startedBy",
              "value": "={{$node[\"Main Workflow Start\"].data[\"startedBy\"]}}"
            }
          ]
        }
      },
      "name": "Use startedBy",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        1270,
        720
      ]
    },
    {
      "parameters": {},
      "name": "Main Workflow Start",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1060,
        720
      ]
    }
  ],
  "connections": {
    "Webhook 1": {
      "main": [
        [
          {
            "node": "Set startedBy 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook 2": {
      "main": [
        [
          {
            "node": "Set startedBy 2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set startedBy 1": {
      "main": [
        [
          {
            "node": "Main Workflow Start",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set startedBy 2": {
      "main": [
        [
          {
            "node": "Main Workflow Start",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Main Workflow Start": {
      "main": [
        [
          {
            "node": "Use startedBy",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Use startedBy": {
      "main": [
        []
      ]
    }
  },
  "active": true,
  "settings": {},
  "id": "2"
}

Here is the simplified and corrected version. Thank you again @jan!