{
  "name": "Time-to-Value Watch",
  "nodes": [
    {
      "id": "67c1784e-3531-48ae-bc12-67a6743d2bbc",
      "name": "Daily Onboarding Check",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        100,
        300
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "40 8 * * 1-5"
            }
          ]
        }
      }
    },
    {
      "id": "8af652f7-c0f7-49fd-a9fc-801cee633fbb",
      "name": "Get Closed Won",
      "type": "n8n-nodes-base.salesforce",
      "typeVersion": 1.1,
      "position": [
        300,
        300
      ],
      "parameters": {
        "resource": "search",
        "operation": "query",
        "query": "SELECT Amount, CloseDate, Account.Name FROM Opportunity WHERE IsWon = true"
      },
      "credentials": {
        "salesforceOAuth2Api": {
          "id": "553Tae1kPe5Wpthq",
          "name": "Salesforce account"
        }
      },
      "executeOnce": true,
      "alwaysOutputData": true
    },
    {
      "id": "59259267-a082-4a43-8cbb-d30e26497e3e",
      "name": "Get Onboarding Accounts",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        500,
        300
      ],
      "parameters": {
        "resource": "row",
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "VGSpF7y1j7T57JqH",
          "cachedResultName": "Onboarding Accounts"
        },
        "returnAll": true
      },
      "executeOnce": true,
      "alwaysOutputData": true
    },
    {
      "id": "561d58dc-2e21-434f-8d8b-5a86990641c8",
      "name": "Get Onboarding Plans",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        700,
        300
      ],
      "parameters": {
        "resource": "row",
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "OseUSm31yPPZP4Vy",
          "cachedResultName": "Onboarding Plans"
        },
        "returnAll": true
      },
      "executeOnce": true,
      "alwaysOutputData": true
    },
    {
      "id": "19970b93-1a1d-42a9-b168-c405207d76f0",
      "name": "Get Milestones",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        900,
        300
      ],
      "parameters": {
        "resource": "row",
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "Os610ph88iK3gHII",
          "cachedResultName": "Onboarding Milestones"
        },
        "returnAll": true
      },
      "executeOnce": true,
      "alwaysOutputData": true
    },
    {
      "id": "a1ef3ac4-6a86-4f9b-88cc-e721c8a90a88",
      "name": "Get Promise Ledger",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        1100,
        300
      ],
      "parameters": {
        "resource": "row",
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "YoJf0J9Hd2WLnA14",
          "cachedResultName": "Promise Ledger"
        },
        "returnAll": true
      },
      "executeOnce": true,
      "alwaysOutputData": true
    },
    {
      "id": "07bacad6-0ea1-4bf5-9cbb-bab22344bdc9",
      "name": "Get Touchpoints",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        1300,
        300
      ],
      "parameters": {
        "resource": "row",
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "4VwFmA1iJIEW3N3N",
          "cachedResultName": "Customer Touchpoints"
        },
        "returnAll": true
      },
      "executeOnce": true,
      "alwaysOutputData": true
    },
    {
      "id": "6474f213-e60f-4d12-8162-03eba198ce6b",
      "name": "Check Milestones",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1500,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "// Time-to-value check, in code. Day 0 is the account's most recent Closed Won date in Salesforce. Every milestone in the\n// product's onboarding plan that is due by today and not done is late. At the day-30 and day-60 checkpoints an account is\n// stalled if the checkpoint's first-value milestone is missing or any milestone is a week or more late; before day 30 a\n// week-late milestone puts it on watch. Overdue promises from the Promise Ledger are attached as extra evidence.\nconst runDate = $today.toFormat('yyyy-MM-dd');\nconst days = (a, b) => Math.round((Date.parse(b + 'T00:00:00Z') - Date.parse(String(a).slice(0, 10) + 'T00:00:00Z')) / 86400000);\nconst addDays = (d, n) => new Date(Date.parse(d + 'T00:00:00Z') + n * 86400000).toISOString().slice(0, 10);\nconst close = {}, value = {};\nfor (const o of $('Get Closed Won').all().map(i => i.json).filter(o => o.Account && o.Account.Name)) {\n  const a = o.Account.Name; if (!close[a] || o.CloseDate > close[a]) close[a] = o.CloseDate; value[a] = (value[a] || 0) + (Number(o.Amount) || 0);\n}\nconst plans = $('Get Onboarding Plans').all().map(i => i.json).filter(p => p.product);\nconst done = {}; for (const m of $('Get Milestones').all().map(i => i.json).filter(m => m.accountName)) done[m.accountName + '|' + m.milestone] = m.completedOn;\nconst promises = $('Get Promise Ledger').all().map(i => i.json).filter(p => p.promiseId && p.status === 'open' && p.dueDate && p.dueDate < runDate);\nconst notes = $('Get Touchpoints').all().map(i => i.json).filter(n => n.accountName);\nconst accounts = [], skipped = [];\nfor (const a of $('Get Onboarding Accounts').all().map(i => i.json).filter(r => r.accountName)) {\n  if (!close[a.accountName]) { skipped.push(a.accountName); continue; }\n  const start = close[a.accountName], day = days(start, runDate);\n  const plan = plans.filter(p => p.product === a.product).sort((x, y) => x.targetDay - y.targetDay);\n  const completed = plan.filter(p => done[a.accountName + '|' + p.milestone]).length;\n  const late = plan.filter(p => p.targetDay <= day && !done[a.accountName + '|' + p.milestone])\n    .map(p => ({ milestone: p.milestone, due: addDays(start, p.targetDay), lateDays: day - p.targetDay, value: Number(p.valueCheckpoint) > 0 }));\n  const stage = day >= 60 ? 'day 60' : day >= 30 ? 'day 30' : 'before day 30';\n  const missedValue = late.filter(l => l.value);\n  const weekLate = late.filter(l => l.lateDays >= 7);\n  const status = stage === 'before day 30' ? (weekLate.length ? 'watch' : 'on track') : (missedValue.length || weekLate.length ? 'stalled' : 'on track');\n  const next = plan.find(p => !done[a.accountName + '|' + p.milestone] && p.targetDay > day);\n  accounts.push({ accountName: a.accountName, product: a.product, csm: a.csm, value: value[a.accountName], closeDate: start, day, stage, status,\n    completed, planSize: plan.length, late, missedValue: missedValue.map(l => l.milestone), next: next ? next.milestone + ' (due ' + addDays(start, next.targetDay) + ')' : '',\n    overduePromises: promises.filter(p => p.accountName === a.accountName).map(p => ({ promise: p.promise, dueDate: p.dueDate, daysOverdue: days(p.dueDate, runDate) })),\n    notesSinceClose: notes.filter(n => n.accountName === a.accountName && n.date >= start).map(n => ({ date: n.date, attendees: n.attendees, notes: n.notes })) });\n}\nconst needReason = accounts.filter(a => a.status !== 'on track').map(a => ({ accountName: a.accountName, lateMilestones: a.late.map(l => l.milestone), notes: a.notesSinceClose }));\nreturn [{ json: { runDate, accounts, skipped, needReason } }];\n"
      },
      "executeOnce": true
    },
    {
      "id": "8770bd4d-f0de-405b-b27c-bc57ad1df872",
      "name": "Blocker Reader",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        300,
        450
      ],
      "parameters": {
        "promptType": "define",
        "text": "={{ JSON.stringify($json.needReason, null, 1) }}",
        "hasOutputParser": true,
        "options": {
          "systemMessage": "You read onboarding notes for Fortavault, Inc. (a fictional data protection company) customers whose implementation is behind plan. For each account you get the milestones that are late and the notes written since the deal closed.\n\nSet blocked to true only if a note says why the work is stuck: a person or approval they are waiting on, a resource gap, a dependency, a pause until a date. Return blocker (one short plain sentence), quote (the exact words from the note that state it, copied word for word) and date (the note's date). If no note explains the delay, return blocked false and empty strings; do not guess a reason. Return one entry per account, using accountName exactly as given."
        }
      },
      "executeOnce": true,
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 2000
    },
    {
      "id": "c3cb5409-76af-40b2-b7aa-348ab40494c3",
      "name": "Claude Sonnet",
      "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
      "typeVersion": 1.3,
      "position": [
        100,
        450
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "claude-sonnet-4-6",
          "cachedResultName": "Claude Sonnet 4.6"
        },
        "options": {
          "temperature": 0
        }
      },
      "credentials": {
        "anthropicApi": {
          "id": "3d3ZiTi7BwnkFwqU",
          "name": "Anthropic account"
        }
      }
    },
    {
      "id": "5bc04ece-2813-4a7c-ad31-09a4b1672ce2",
      "name": "Blocker Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.3,
      "position": [
        100,
        600
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n \"type\": \"object\",\n \"properties\": {\n  \"accounts\": {\n   \"type\": \"array\",\n   \"items\": {\n    \"type\": \"object\",\n    \"properties\": {\n     \"accountName\": {\n      \"type\": \"string\"\n     },\n     \"blocked\": {\n      \"type\": \"boolean\"\n     },\n     \"blocker\": {\n      \"type\": \"string\"\n     },\n     \"quote\": {\n      \"type\": \"string\"\n     },\n     \"date\": {\n      \"type\": \"string\"\n     }\n    },\n    \"required\": [\n     \"accountName\",\n     \"blocked\",\n     \"blocker\",\n     \"quote\",\n     \"date\"\n    ]\n   }\n  }\n },\n \"required\": [\n  \"accounts\"\n ]\n}"
      }
    },
    {
      "id": "e9de8920-558d-46c6-828b-0e7362656b05",
      "name": "Build Watch Digest",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        500,
        450
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "// Attach the blocker Claude found (kept only if its quote is word for word in that account's notes) and build the digest.\nconst c = $('Check Milestones').first().json;\nconst out = $('Blocker Reader').first().json.output || {};\nconst norm = s => String(s || '').replace(/[‘’]/g, \"'\").replace(/[“”]/g, '\"').replace(/\\s+/g, ' ').trim().toLowerCase();\nconst safe = t => String(t || '').replace(/~/g, '≈');\nconst read = {}; for (const r of (out.accounts || [])) read[r.accountName] = r;\nlet unverified = 0;\nconst rows = c.accounts.map(a => {\n  const r = read[a.accountName] || {};\n  const all = norm(a.notesSinceClose.map(n => n.notes).join(' '));\n  const ok = r.blocked && r.quote && norm(r.quote).length >= 12 && all.includes(norm(r.quote));\n  if (r.blocked && !ok) unverified++;\n  return { ...a, blocker: ok ? r.blocker : '', quote: ok ? r.quote.trim() : '', quoteDate: ok ? r.date : '' };\n});\nconst money = n => '$' + Math.round((n || 0) / 1000) + 'K';\nconst block = a => '*' + a.accountName + '* · ' + a.product + ' · day ' + a.day + ' (closed ' + a.closeDate + ', ' + money(a.value) + ' Closed Won) · CSM ' + a.csm + ' · ' + a.completed + ' of ' + a.planSize + ' milestones done\\n' +\n  a.late.map(l => '      • ' + (l.value ? '*' + l.milestone + '* (first value)' : l.milestone) + ': due ' + l.due + ', ' + (l.lateDays ? l.lateDays + ' days late' : 'due today')).join('\\n') +\n  (a.quote ? '\\n      Blocker (' + a.quoteDate + '): _“' + safe(a.quote) + '”_' : (a.status !== 'on track' ? '\\n      Blocker: _nothing in the notes explains it; the CSM should ask this week_' : '')) +\n  (a.overduePromises.length ? '\\n      :rotating_light: Also overdue from the sale: ' + a.overduePromises.map(p => p.promise + ' (' + p.daysOverdue + ' days)').join('; ') : '');\nconst stalled = rows.filter(r => r.status === 'stalled').sort((a, b) => b.day - a.day), watch = rows.filter(r => r.status === 'watch'), ok = rows.filter(r => r.status === 'on track');\nlet text = ':hourglass_flowing_sand: *Time-to-Value Watch* (' + c.runDate + '): ' + rows.length + ' accounts in onboarding, measured from their Closed Won date in Salesforce.\\n' +\n  (stalled.length ? '\\n*Stalled at a checkpoint* (' + stalled.length + '), before any revenue signal has moved\\n' + stalled.map(a => '_' + a.stage + ' checkpoint_ ' + block(a)).join('\\n\\n') + '\\n' : '') +\n  (watch.length ? '\\n*On watch, before day 30* (' + watch.length + ')\\n' + watch.map(block).join('\\n\\n') + '\\n' : '') +\n  '\\n*On track* (' + ok.length + '): ' + ok.map(a => a.accountName + ' (day ' + a.day + (a.next ? ', next: ' + a.next : '') + ')').join(' · ') +\n  (unverified ? '\\n_' + unverified + ' blocker(s) dropped: quote not found in the notes._' : '') +\n  (c.skipped.length ? '\\n_Skipped (no Closed Won deal in Salesforce): ' + c.skipped.join(', ') + '._' : '');\nif (text.length > 2900) text = text.slice(0, 2850).slice(0, text.slice(0, 2850).lastIndexOf('\\n')) + '\\n_…cut to fit Slack; every account is in the Time-to-Value Log._';\nconst now = $now.toISO();\nconst logs = rows.map(r => ({ runDate: c.runDate, accountName: r.accountName, product: r.product, day: r.day, stage: r.stage, status: r.status,\n  lateMilestones: r.late.map(l => l.milestone + ' (' + l.lateDays + 'd)').join('; '), blocker: r.blocker, quote: r.quote, overduePromises: r.overduePromises.length, loggedAt: now }));\nreturn [{ json: { digestText: text, logs, statuses: rows.map(r => [r.accountName, r.day, r.status]) } }];\n"
      },
      "executeOnce": true
    },
    {
      "id": "13628ee1-4f18-4bcb-9e3d-c50dee698549",
      "name": "Post Time-to-Value Watch",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.7,
      "position": [
        700,
        450
      ],
      "parameters": {
        "resource": "message",
        "operation": "post",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "C0BQ3G96HL6",
          "cachedResultName": "general"
        },
        "text": "={{ $json.digestText }}",
        "otherOptions": {
          "includeLinkToWorkflow": false
        }
      },
      "credentials": {
        "slackApi": {
          "id": "mv7TIi8kucFPqPg6",
          "name": "Slack account"
        }
      }
    },
    {
      "id": "1cf9543b-8ed5-444b-a0a0-37f99d4a26f0",
      "name": "Split Log Rows",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        700,
        600
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "return $('Build Watch Digest').first().json.logs.map(json => ({ json }));"
      }
    },
    {
      "id": "05d8f39e-dc3f-4268-8166-ca7ad30568c9",
      "name": "Log Time-to-Value",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        900,
        600
      ],
      "parameters": {
        "resource": "row",
        "operation": "insert",
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "6bTbiZaKycQYcaee",
          "cachedResultName": "Time-to-Value Log"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {}
        }
      }
    }
  ],
  "connections": {
    "Daily Onboarding Check": {
      "main": [
        [
          {
            "node": "Get Closed Won",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Closed Won": {
      "main": [
        [
          {
            "node": "Get Onboarding Accounts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Onboarding Accounts": {
      "main": [
        [
          {
            "node": "Get Onboarding Plans",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Onboarding Plans": {
      "main": [
        [
          {
            "node": "Get Milestones",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Milestones": {
      "main": [
        [
          {
            "node": "Get Promise Ledger",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Promise Ledger": {
      "main": [
        [
          {
            "node": "Get Touchpoints",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Touchpoints": {
      "main": [
        [
          {
            "node": "Check Milestones",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Milestones": {
      "main": [
        [
          {
            "node": "Blocker Reader",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Blocker Reader": {
      "main": [
        [
          {
            "node": "Build Watch Digest",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Claude Sonnet": {
      "ai_languageModel": [
        [
          {
            "node": "Blocker Reader",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Blocker Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Blocker Reader",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Build Watch Digest": {
      "main": [
        [
          {
            "node": "Post Time-to-Value Watch",
            "type": "main",
            "index": 0
          },
          {
            "node": "Split Log Rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Log Rows": {
      "main": [
        [
          {
            "node": "Log Time-to-Value",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}