{
  "name": "Audit service-request queues and export a CSV review",
  "nodes": [
    {
      "name": "Start queue review",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "parameters": {},
      "position": [
        0,
        280
      ],
      "id": "starter"
    },
    {
      "name": "Configure queue review",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "parameters": {
        "mode": "raw",
        "jsonOutput": "{\n  \"referenceDate\": \"2026-11-20\",\n  \"rows\": [\n    {\n      \"id\": \"REQ-001\",\n      \"request\": \"Replace the demo kiosk label\",\n      \"status\": \"new\",\n      \"owner\": \"Alex\",\n      \"dueDate\": \"2026-11-21\"\n    },\n    {\n      \"id\": \"REQ-002\",\n      \"request\": \"Review the sample access request\",\n      \"status\": \"in_progress\",\n      \"owner\": \"\",\n      \"dueDate\": \"2026-11-19\"\n    },\n    {\n      \"id\": \"REQ-003\",\n      \"request\": \"Close the practice onboarding task\",\n      \"status\": \"done\",\n      \"owner\": \"\",\n      \"dueDate\": \"2026-11-18\"\n    },\n    {\n      \"id\": \"REQ-004\",\n      \"request\": \"Check the fictional room display\",\n      \"status\": \"new\",\n      \"owner\": \"Mira\",\n      \"dueDate\": \"2026-11-22\"\n    },\n    {\n      \"id\": \"REQ-004\",\n      \"request\": \"Check the fictional printer label\",\n      \"status\": \"new\",\n      \"owner\": \"Sam\",\n      \"dueDate\": \"2026-11-22\"\n    },\n    {\n      \"id\": \"\",\n      \"request\": \"\",\n      \"status\": \"waiting\",\n      \"owner\": \"\",\n      \"dueDate\": \"2026-02-30\"\n    }\n  ]\n}",
        "options": {}
      },
      "position": [
        240,
        280
      ],
      "id": "configure"
    },
    {
      "name": "Audit service requests",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "function auditServiceRequests(snapshot) {\n  function isObject(value) {\n    return value !== null && typeof value === 'object' && !Array.isArray(value)\n  }\n  function isDate(value) {\n    if (typeof value !== 'string' || !/^\\d{4}-\\d{2}-\\d{2}$/.test(value)) return false\n    const parsed = new Date(`${value}T00:00:00.000Z`)\n    return Number.isFinite(parsed.getTime()) && parsed.toISOString().slice(0, 10) === value\n  }\n  function text(value) {\n    return typeof value === 'string' ? value.trim() : ''\n  }\n  if (!isObject(snapshot)) throw new Error('Expected one object with referenceDate and rows.')\n  if (!isDate(snapshot.referenceDate))\n    throw new Error('referenceDate must be a real YYYY-MM-DD date.')\n  if (!Array.isArray(snapshot.rows))\n    throw new Error('rows must be an array, including [] for an empty queue.')\n  if (snapshot.rows.length > 2000)\n    throw new Error('Review at most 2000 rows per snapshot; check source completeness separately.')\n  const records = snapshot.rows.map((row, index) => {\n    if (!isObject(row)) throw new Error(`rows[${index}] must be an object.`)\n    const flags = []\n    let id = ''\n    if (typeof row.id === 'string') id = row.id.trim()\n    else if (Number.isSafeInteger(row.id)) id = String(row.id)\n    else if (row.id !== null && row.id !== undefined) flags.push('invalid_id')\n    if (!id && !flags.includes('invalid_id')) flags.push('missing_id')\n    const request = text(row.request)\n    const status = text(row.status)\n    const owner = text(row.owner)\n    const dueDate = text(row.dueDate)\n    if (!request) flags.push('missing_request')\n    const active = status === 'new' || status === 'in_progress'\n    if (!active && status !== 'done') flags.push('unknown_status')\n    if (active && !owner) flags.push('unassigned')\n    const hasDueDate = row.dueDate !== null && row.dueDate !== undefined && row.dueDate !== ''\n    const validDueDate = isDate(dueDate)\n    if (hasDueDate && !validDueDate) flags.push('invalid_due_date')\n    const overdue = active && validDueDate && dueDate < snapshot.referenceDate\n    if (overdue) flags.push('overdue')\n    return { sourceRow: index + 1, id, request, status, owner, dueDate, overdue, flags }\n  })\n  const counts = new Map()\n  for (const record of records)\n    if (record.id) counts.set(record.id, (counts.get(record.id) || 0) + 1)\n  const dataFlags = new Set([\n    'missing_id',\n    'invalid_id',\n    'duplicate_id',\n    'missing_request',\n    'unknown_status',\n    'invalid_due_date',\n  ])\n  for (const record of records) {\n    if (record.id && counts.get(record.id) > 1) record.flags.push('duplicate_id')\n    record.needsReview = record.flags.length > 0\n    record.recommendation = record.flags.some((flag) => dataFlags.has(flag))\n      ? 'Hold: correct data before automation'\n      : record.flags.includes('unassigned')\n        ? record.overdue\n          ? 'Assign owner and review overdue request'\n          : 'Assign an owner'\n        : record.overdue\n          ? 'Review overdue request'\n          : record.status === 'done'\n            ? 'Closed: no next action'\n            : 'Ready for the next step'\n  }\n  return {\n    referenceDate: snapshot.referenceDate,\n    summary: {\n      totalRows: records.length,\n      cleanRows: records.filter((row) => !row.needsReview).length,\n      reviewRows: records.filter((row) => row.needsReview).length,\n      overdueRows: records.filter((row) => row.overdue).length,\n      unassignedRows: records.filter((row) => row.flags.includes('unassigned')).length,\n      duplicateIdRows: records.filter((row) => row.flags.includes('duplicate_id')).length,\n      duplicateIds: [...counts.values()].filter((count) => count > 1).length,\n    },\n    records,\n  }\n}\nreturn [{ json: auditServiceRequests($input.first().json) }];"
      },
      "position": [
        520,
        280
      ],
      "id": "audit"
    },
    {
      "name": "Build CSV review rows",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "function serviceRequestCsvRows(audit) {\n  // A report, not a source-data round trip. Raw values remain in the audit node.\n  function cell(value) {\n    if (typeof value !== 'string') return value\n    return /^[\\s\\uFEFF]*[=+@-]/.test(value) || /^[\\t\\r\\n]/.test(value) ? `'${value}` : value\n  }\n  const common = {\n    row_type: 'summary',\n    reference_date: audit.referenceDate,\n    source_row: '',\n    id: '',\n    request: '',\n    status: '',\n    owner: '',\n    due_date: '',\n    overdue: '',\n    needs_review: '',\n    flags: '',\n    recommendation: '',\n    total_rows: audit.summary.totalRows,\n    clean_rows: audit.summary.cleanRows,\n    review_rows: audit.summary.reviewRows,\n    overdue_rows: audit.summary.overdueRows,\n    unassigned_rows: audit.summary.unassignedRows,\n    duplicate_id_rows: audit.summary.duplicateIdRows,\n    duplicate_ids: audit.summary.duplicateIds,\n  }\n  return [\n    common,\n    ...audit.records.map((row) => ({\n      ...common,\n      row_type: 'request',\n      source_row: row.sourceRow,\n      id: cell(row.id),\n      request: cell(row.request),\n      status: cell(row.status),\n      owner: cell(row.owner),\n      due_date: cell(row.dueDate),\n      overdue: row.overdue,\n      needs_review: row.needsReview,\n      flags: row.flags.join('; '),\n      recommendation: row.recommendation,\n      total_rows: '',\n      clean_rows: '',\n      review_rows: '',\n      overdue_rows: '',\n      unassigned_rows: '',\n      duplicate_id_rows: '',\n      duplicate_ids: '',\n    })),\n  ]\n}\nreturn serviceRequestCsvRows($input.first().json).map(json => ({ json }));"
      },
      "position": [
        780,
        280
      ],
      "id": "report"
    },
    {
      "name": "Download review CSV",
      "type": "n8n-nodes-base.convertToFile",
      "typeVersion": 1.2,
      "parameters": {
        "operation": "csv",
        "binaryPropertyName": "data",
        "options": {
          "delimiter": ",",
          "headerRow": true,
          "fileName": "service-request-review.csv"
        }
      },
      "position": [
        1040,
        280
      ],
      "id": "download"
    },
    {
      "name": "Read first",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "parameters": {
        "content": "### How it works\nReview a service-request snapshot before attaching notifications or record updates. A manual trigger loads six fictional requests, checks IDs, duplicate IDs, request text, status, assignment and due dates, then creates a CSV with a summary and every supplied row. Nothing is sent or written to an external service.\n\n### Setup\nNo accounts, API credentials or community nodes are required for the included example. Tested on n8n 2.47.7. Open Configure queue review and change referenceDate to your review date (YYYY-MM-DD). Keep the six example rows for the first run. Execute the workflow, inspect Audit service requests and download the binary output from Download review CSV. Expect 6 rows, 4 needing review, 1 overdue, and 2 rows sharing one duplicate ID.\n\n### Customization\nReplace rows with an authorized snapshot from your request system. Map only id, request, status, owner and dueDate; use new, in_progress or done. Dates are calendar dates, not timestamps. Missing due dates are allowed; active requests need an owner. The limit is 2000 supplied rows: this does not fetch pages or prove source completeness. Empty input produces a summary-only CSV. Invalid structure stops with an error. Repeating the same snapshot and review date produces the same report. Formula-like CSV text is prefixed with an apostrophe; raw values stay in the audit node. Review execution retention before using private data.\n\n[Walkthrough and AppStruct source option](https://blog.appstruct.ai/blog/n8n-service-request-queue-audit?utm_source=n8n_template&utm_medium=referral&utm_campaign=queue_audit_20261120&utm_content=overview)",
        "color": 1,
        "width": 510,
        "height": 810
      },
      "position": [
        -600,
        -110
      ],
      "id": "overview"
    },
    {
      "name": "Provide one snapshot",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "parameters": {
        "content": "## Provide one snapshot\nSet an explicit review date and a rows array. All included records are fictional. No connection is required.",
        "color": 7,
        "width": 510,
        "height": 390
      },
      "position": [
        -70,
        90
      ],
      "id": "input-section"
    },
    {
      "name": "Inspect issues before acting",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "parameters": {
        "content": "## Validate request data\nFlag duplicate IDs, invalid fields, missing owners and overdue dates. Keep every supplied row.",
        "color": 7,
        "width": 260,
        "height": 390
      },
      "position": [
        450,
        90
      ],
      "id": "audit-section"
    },
    {
      "name": "Export a review report",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "parameters": {
        "content": "## Export a review report\nOne summary row plus every request. Download the CSV binary output; empty queues still produce a summary. No messages or source updates.",
        "color": 7,
        "width": 510,
        "height": 390
      },
      "position": [
        720,
        90
      ],
      "id": "output-section"
    }
  ],
  "connections": {
    "Start queue review": {
      "main": [
        [
          {
            "node": "Configure queue review",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Configure queue review": {
      "main": [
        [
          {
            "node": "Audit service requests",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Audit service requests": {
      "main": [
        [
          {
            "node": "Build CSV review rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build CSV review rows": {
      "main": [
        [
          {
            "node": "Download review CSV",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "tags": []
}
