{
  "name": "AI Vanguard | Delivery to invoice",
  "nodes": [
    {
      "id": "f6ea6170-50f1-41ab-8e68-f715e53228f9",
      "name": "Run sample now",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "parameters": {}
    },
    {
      "id": "ed35f1a6-3bf8-41dd-93e9-2d51b8bcc0a6",
      "name": "Run on schedule",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.3,
      "position": [
        0,
        180
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 */2 * * *"
            }
          ]
        }
      }
    },
    {
      "id": "810c3dac-937e-4290-ada1-0cfdce7a3cf7",
      "name": "Spreadsheet ID",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        240,
        90
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "cb9a97b0-ee6a-4d64-ac48-95a23d838ca5",
              "name": "spreadsheetId",
              "value": "REPLACE_WITH_YOUR_SHEET_ID",
              "type": "string"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "b21833d8-bfb5-4bfd-ae92-29abed71a003",
      "name": "Read Input rows",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        480,
        90
      ],
      "parameters": {
        "authentication": "oAuth2",
        "resource": "sheet",
        "operation": "read",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Spreadsheet ID').first().json.spreadsheetId }}"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Input"
        },
        "options": {
          "outputFormatting": {
            "values": {
              "general": "UNFORMATTED_VALUE",
              "date": "FORMATTED_STRING"
            }
          }
        }
      }
    },
    {
      "id": "005fd5fa-3a2e-40b5-acc7-4585aba2d29d",
      "name": "Keep exceptions with a case key",
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        720,
        90
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "a2d3da9e-e5cc-412f-bf56-8b6f24038749",
              "leftValue": "={{ String($json['Case key'] ?? '').trim() }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            },
            {
              "id": "a2c9bdbf-a56f-4837-93fc-637b5ef3a4b9",
              "leftValue": "={{ String($json['Exception'] ?? '').trim() }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "5635cf4f-0c2a-4e11-a5ed-2766175c8685",
      "name": "Normalize the case key",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        960,
        90
      ],
      "parameters": {
        "includeOtherFields": true,
        "assignments": {
          "assignments": [
            {
              "id": "78233436-0591-4e03-8f4c-6377754e1a65",
              "name": "Case key",
              "value": "={{ String($json['Case key']).trim().toLowerCase() }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "2f1f9377-5655-46e4-a690-5fb0ee782cb1",
      "name": "Keep one row per case",
      "type": "n8n-nodes-base.removeDuplicates",
      "typeVersion": 2,
      "position": [
        1200,
        90
      ],
      "parameters": {
        "operation": "removeDuplicateInputItems",
        "compare": "selectedFields",
        "fieldsToCompare": "Case key",
        "options": {}
      }
    },
    {
      "id": "4c494df9-6d4d-4d7b-a94f-4e94cc1b3af1",
      "name": "Put exceptions in Review Queue",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        1440,
        90
      ],
      "parameters": {
        "authentication": "oAuth2",
        "resource": "sheet",
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Spreadsheet ID').first().json.spreadsheetId }}"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Review Queue"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Case key": "={{ String($json['Case key']).trim().toLowerCase() }}",
            "Exception": "={{ $json['Exception'] }}",
            "Evidence": "={{ $json['Evidence'] }}",
            "Owner": "={{ $json['Owner for review'] }}",
            "Next step": "={{ $json['Next step'] }}",
            "Last seen": "={{ $now.toISO() }}"
          },
          "matchingColumns": [
            "Case key"
          ],
          "schema": [
            {
              "id": "Case key",
              "displayName": "Case key",
              "required": false,
              "defaultMatch": true,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Exception",
              "displayName": "Exception",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Evidence",
              "displayName": "Evidence",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Owner",
              "displayName": "Owner",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Next step",
              "displayName": "Next step",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Last seen",
              "displayName": "Last seen",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Review status",
              "displayName": "Review status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Reviewer notes",
              "displayName": "Reviewer notes",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {
          "cellFormat": "RAW",
          "useAppend": true
        }
      }
    }
  ],
  "connections": {
    "Run sample now": {
      "main": [
        [
          {
            "node": "Spreadsheet ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run on schedule": {
      "main": [
        [
          {
            "node": "Spreadsheet ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Spreadsheet ID": {
      "main": [
        [
          {
            "node": "Read Input rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Input rows": {
      "main": [
        [
          {
            "node": "Keep exceptions with a case key",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Keep exceptions with a case key": {
      "main": [
        [
          {
            "node": "Normalize the case key",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize the case key": {
      "main": [
        [
          {
            "node": "Keep one row per case",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Keep one row per case": {
      "main": [
        [
          {
            "node": "Put exceptions in Review Queue",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "timezone": "Asia/Amman",
    "saveManualExecutions": false
  }
}
