Catch a variable value in a n-2 Function node through Switch?

WF contains Function then Swicth then ExecuteCommand
In the Function node I set up a local hash whose I need a member in the ExecuteCommand
I could put this value in Function output to make it travel but the Switch stops it because it only accepts limited integers on output
How could I do without setting up a gaz plant, and easy to maintain ?

Hey @minstrel!

The switch node doesn’t limit the output. It the condition is not met, it will not give the output. Make sure that the condition you have is satisfied and returns an output to the case (0,1,2,3) you mention. You can read more about the Switch node here.

Also if you can, please share the workflow here. I will take a look and see if there is anything else that is preventing the correct output. :slightly_smiling_face:

Hi harshil

Maybe I was not clear …
Here the Swicth node, you see the outDiag of the diagOnActive Function node as input value
You also see that outputs are just integers
So I can’t see at all how can I pass my hash value defined in the Function node to the nodes following the Switch ?

{
      "parameters": {
        "dataType": "string",
        "value1": "={{$node[\"diagOnActive\"].json[\"outDiag\"]}}",
        "rules": {
          "rules": [
            {
              "operation": "contains",
              "value2": "AGENT-ERROR",
              "output": 2
            },
            {
              "operation": "contains",
              "value2": "BDD_ERROR"
            },
            {
              "operation": "contains",
              "value2": "COLLECTOR_ERROR",
              "output": 1
            },
            {
              "operation": "contains",
              "value2": "NO-ERROR",
              "output": 3
            }
          ]
        }      },
     "name": "whatError ?",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 1,
      "position": [
        -90,
        500
      ],
      "notesInFlow": true
    },

Hey,

Can you please check the workflow you shared? It looks incomplete.

A minimalist use case here showing my request, to make it simpler : how to pass ap["active"] value to the first Set node ?

I ran the Function node and found out that you have only added outDiag to the items, and as a result, the Function node only gives outDiag as the output.

[
  {        
    "outDiag": "NO-ERROR"      
  }    
]

I have modified the workflow you shared.

Hope this helps. :slightly_smiling_face:

1 Like

Of course harshil, by referencing any node output in whole WF …
Sorry it’s not a yet a reflex :no_mouth: thanks !