Is there a way to check that another previous node is active (e.g. a Google Drive node) within the function node?
Hey @pb84, I don’t think there’s currently an easy way to query the status of a node I am afraid.
A hacky approach would be to first download the current workflow JSON (check this topic for details on how to do this using the new user management functionality) and then parse the workflow JSON to check the status of an individual node.
For example like so (make sure to save your workflow before testing this):
Note that the UI API used here is undocumented and can change without notice in the future, so be careful when upgrading n8n.
Thanks!
I was thinking, is it possible, to use some sort of try function within javascript and if it fails (on the module not being available) that work as a defacto solution - however haven’t been able to get this to work
Thought I’d share a crisp solution that I developed
{
"nodes": [
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
240,
300
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "#",
"options": {}
},
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 1,
"position": [
240,
480
],
"webhookId": "#",
"disabled": true
},
{
"parameters": {
"functionCode": "var data;\n\ntry {\n data = "#" \n}\n\nreturn data;"
},
"name": "Function",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
460,
480
]
}
],
"connections": {
"Start": {
"main": [
[
{
"node": "Function",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "Function",
"type": "main",
"index": 0
}
]
]
}
}
}
Using JS try catch, can manage this very well - very useful for building workflows with webhooks and not having to constantly re-run the webhook
Neat, thanks so much for sharing!
Out of interest, how do you get the flow to display in the forum as a ‘flow’ rather than code?
It shows up as code rather than a workflow because n8n doesn’t see it out of the box as a workflow. It seems two quotes aren’t properly escaped - did you by any chance remove something confidential from your code manually?
Once you add a backslash before each double quote around the #
it shows up as a workflow:
Ah that makes a lot of sense - yep thats exactly what i did