DEV Community

Cover image for Decision Making in n8n

Decision Making in n8n

Switch Case

Imagine you need a switch case in your n8n to go and use different nodes to go further. In n8n we have switch core node:

{
  "name": "My workflow",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "value": "1wYhSMlUiG-0v17fBLassXoNblOueJSdM",
          "mode": "list",
          "cachedResultName": "temp",
          "cachedResultUrl": "https://drive.google.com/drive/folders/1wYhSMlUiG-0v17fBLassXoNblOueJSdM"
        },
        "event": "fileCreated",
        "options": {}
      },
      "id": "14fc3f4f-ff03-432b-bf55-6110a6486749",
      "name": "Google Drive Trigger",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "alwaysOutputData": true,
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "ylcbOOCDwzWsz65i",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "operation": "download",
        "fileId": {
          "__rl": true,
          "value": "={{ $json.id }}",
          "mode": "id"
        },
        "options": {
          "googleFileConversion": {
            "conversion": {
              "docsToFormat": "text/plain",
              "slidesToFormat": "application/pdf"
            }
          }
        }
      },
      "id": "a4645eec-f469-4a7c-92dc-27d8b463d2b1",
      "name": "Download file",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        224,
        0
      ],
      "alwaysOutputData": true,
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "ylcbOOCDwzWsz65i",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.mimeType }}",
                    "rightValue": "application/vnd.google-apps.document",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "3b95c38d-4160-44ad-8c2b-b3c6735554bc"
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "36a5eb5c-ff54-480d-93f8-328c61914788",
                    "leftValue": "={{ $json.mimeType }}",
                    "rightValue": "application/pdf",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "fdeb76a1-fd81-4da1-930f-c69dea81bef6",
                    "leftValue": "={{ $json.mimeType }}",
                    "rightValue": "application/vnd.google-apps.spreadsheet",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              }
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        416,
        -16
      ],
      "id": "607da32c-b562-409e-bd30-37aca3410ee0",
      "name": "Switch"
    },
    {
      "parameters": {
        "operation": "text",
        "options": {}
      },
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1.1,
      "position": [
        720,
        -96
      ],
      "id": "76f336e0-b2c8-4ac8-9376-831e5fc9e9a7",
      "name": "Extract from Text file"
    },
    {
      "parameters": {
        "operation": "pdf",
        "options": {}
      },
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1.1,
      "position": [
        720,
        64
      ],
      "id": "16f76e76-b53b-4460-a800-a4314fe3271f",
      "name": "Extract from PDF File"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1.1,
      "position": [
        720,
        240
      ],
      "id": "57a6940a-2912-4ba5-84cd-1f7e3d9848f0",
      "name": "Extract from CSV File"
    }
  ],
  "pinData": {},
  "connections": {
    "Google Drive Trigger": {
      "main": [
        [
          {
            "node": "Download file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download file": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Extract from Text file",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract from PDF File",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract from CSV File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": false
  },
  "versionId": "f5b5ac81-064b-41c2-aaa1-809ec10b2331",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "d7f40ac67c918c6b77c1db2f31baa37e504a493b4a22e372f2a513b7bf0ca5a9"
  },
  "nodeGroups": [],
  "id": "jqcICzVZI18I6JQb",
  "tags": []
}
Enter fullscreen mode Exit fullscreen mode

n8n switch node

Top comments (0)