{
  "elementsLearnedData": [],
  "elementsTestData": [],
  "flow": {
    "id": "5154DC52-43BF-4C7B-9BF5-2A5EE798A18F",
    "name": "Acumatica: daily AP health check"
  },
  "flowVersion": {
    "clientMetadata": {
      "viewport": {
        "x": 170.875,
        "y": 51,
        "zoom": 1
      },
      "autoSave": true,
      "descriptions": {
        "flow": "Each morning, reads the AP aging balance and the open bills in Acumatica and posts one summary to the finance channel in Slack: total payables, bills due in the next 7 days, and vendors with overdue balances.",
        "initialData": "",
        "initialDataFields": {}
      }
    },
    "description": "Each morning, reads the AP aging balance and the open bills in Acumatica and posts one summary to the finance channel in Slack: total payables, bills due in the next 7 days, and vendors with overdue balances.",
    "elements": [
      {
        "clientMetadata": {
          "elementId": "custom-cloud-code",
          "isFirstElement": false,
          "blockDefinitionId": "custom-cloud-code",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Write the daily summary Result"
          },
          "position": {
            "x": 101.125,
            "y": 291
          }
        },
        "flowElementId": "C88C2F3F-5EA4-4C54-9D3A-D50A95F51BB0",
        "groupId": null,
        "id": "03F5E517-63D3-4B90-A6A6-579D602C0F00",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "codeArguments": [
            {
              "name": "aging",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "AP aging",
                    "subPathSegments": null,
                    "type": "ELEMENT_LINK",
                    "value": "694795DC-560D-4C7A-A3DF-B17C59377DF7"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "bills",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Open bills",
                    "subPathSegments": null,
                    "type": "ELEMENT_LINK",
                    "value": "D8A1D042-CBD5-4558-A5E9-19F0B55BFDE5"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "codeBody": {
            "expression": [
              {
                "id": "TEXT",
                "label": null,
                "type": "INPUT",
                "value": "const fmt = (n) => '$' + Number(n || 0).toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 });\nconst DAY = 86400000;\nconst today = new Date();\ntoday.setUTCHours(0, 0, 0, 0);\nconst weekOut = new Date(today.getTime() + 7 * DAY);\nconst day = (d) => d.toISOString().slice(0, 10);\n\nconst agingRows = Array.isArray(aging?.ReportResults) ? aging.ReportResults : [];\nconst vendorNames = {};\nfor (const row of agingRows) {\n  if (row.VendorID?.value) vendorNames[row.VendorID.value] = row.VendorName?.value || row.VendorID.value;\n}\nconst name = (id) => vendorNames[id] || id;\n\nconst open = (Array.isArray(bills) ? bills : []).map((b) => ({\n  ref: b.ReferenceNbr?.value,\n  vendor: b.Vendor?.value || '',\n  vendorRef: b.VendorRef?.value || '',\n  balance: Number(b.Balance?.value ?? b.Amount?.value) || 0,\n  due: b.DueDate?.value ? new Date(b.DueDate.value) : null,\n})).filter((b) => b.ref && b.balance);\n\nconst agingTotal = agingRows.reduce((sum, r) => sum + (Number(r.TotalDue?.value ?? r.CurrentBalance?.value) || 0), 0);\nconst apTotal = agingRows.length ? agingTotal : open.reduce((sum, b) => sum + b.balance, 0);\n\nconst dueSoon = open.filter((b) => b.due && b.due >= today && b.due <= weekOut).sort((a, b) => a.due - b.due);\nconst overdue = open.filter((b) => b.due && b.due < today);\nconst byVendor = {};\nfor (const b of overdue) {\n  const v = byVendor[b.vendor] || (byVendor[b.vendor] = { count: 0, amount: 0, oldest: b.due });\n  v.count += 1;\n  v.amount += b.balance;\n  if (b.due < v.oldest) v.oldest = b.due;\n}\nconst overdueVendors = Object.entries(byVendor).sort((a, b) => b[1].amount - a[1].amount);\n\nconst lines = [\n  `*AP health check for ${day(today)}*`,\n  `Total open payables: ${fmt(apTotal)}`,\n  '',\n  `*Due in the next 7 days:* ${dueSoon.length} bill${dueSoon.length === 1 ? '' : 's'}, ${fmt(dueSoon.reduce((s, b) => s + b.balance, 0))}`,\n  ...dueSoon.slice(0, 15).map((b) => `${day(b.due)}  ${name(b.vendor)}, invoice ${b.vendorRef || b.ref}, ${fmt(b.balance)}`),\n  dueSoon.length > 15 ? `and ${dueSoon.length - 15} more` : null,\n  '',\n  overdueVendors.length\n    ? `*Vendors with overdue balances:* ${overdueVendors.length}, ${fmt(overdue.reduce((s, b) => s + b.balance, 0))} in total`\n    : '*No overdue bills.*',\n  ...overdueVendors.slice(0, 15).map(([vendor, v]) => `${name(vendor)}: ${fmt(v.amount)} on ${v.count} bill${v.count === 1 ? '' : 's'}, oldest due ${day(v.oldest)}`),\n  overdueVendors.length > 15 ? `and ${overdueVendors.length - 15} more vendors` : null,\n].filter((line) => line !== null);\n\nreturn { text: lines.join('\\n'), apTotal, dueSoonCount: dueSoon.length, overdueVendorCount: overdueVendors.length };"
              }
            ],
            "mode": "EXPRESSION",
            "parseJsonString": false,
            "resultType": null
          },
          "enabled": true,
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "onFailElemId": null,
          "resultAlias": "Daily summary",
          "retryPolicy": null,
          "saveToVariable": null,
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "type": "CUSTOM_CLOUD_CODE"
        },
        "name": "Write the daily summary",
        "nextElementIds": [
          "309DD03D-4407-47F0-ACA9-E39222849FF8"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "notes": "Sends messages to Slack channels with optional Block Kit rich layouts. Supports plain text with Slack formatting, or advanced Block Kit JSON for buttons, menus, and interactive elements. Returns the message timestamp and channel ID for later updates or tracking.",
          "elementId": "EXTENSION:::SHARED:::default:::slack:::sendMessageToChannel",
          "isFirstElement": false,
          "dynamicOptionLabels": {
            "channelId": {}
          },
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Post the summary to finance Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::slack:::sendMessageToChannel",
          "legacyElementId": "JS###v1###Slack###sendMessageToChannel",
          "methodName": "sendMessageToChannel",
          "position": {
            "x": 87,
            "y": 407
          }
        },
        "flowElementId": "DCC790EF-197F-4073-A711-583CDA3CCE18",
        "groupId": null,
        "id": "309DD03D-4407-47F0-ACA9-E39222849FF8",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "channelId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": ""
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "messageText",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Daily summary",
                    "subPathSegments": [
                      {
                        "key": "text",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "03F5E517-63D3-4B90-A6A6-579D602C0F00"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "threadId",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "sendAsBot",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "K_FALSE",
                    "label": null,
                    "type": "KEYWORD",
                    "value": false
                  }
                ],
                "mode": "BASIC",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "botName",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "botIcon",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "replyBroadcast",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "K_FALSE",
                    "label": null,
                    "type": "KEYWORD",
                    "value": false
                  }
                ],
                "mode": "BASIC",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "imageURL",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "blocks",
              "type": "COMPLEX_LIST",
              "value": []
            }
          ],
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "sendMessageToChannel",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Summary posted",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "slack",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Post the summary to finance",
        "nextElementIds": [],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "notes": "Retrieves the AP Aging Summary report (AP632000) from Acumatica showing outstanding balances by vendor. Optionally filter by a specific vendor to see their aging buckets and total outstanding amount.",
          "elementId": "EXTENSION:::SHARED:::default:::acumatica:::getAPAccountBalance",
          "isFirstElement": true,
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Get the AP balance Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::acumatica:::getAPAccountBalance",
          "legacyElementId": "JS###v1###AcumaticaService###getAPAccountBalance",
          "methodName": "getAPAccountBalance",
          "position": {
            "x": 110,
            "y": 40
          }
        },
        "flowElementId": "CC2CB0A5-CE1B-4844-A427-8AF94F32C03C",
        "groupId": null,
        "id": "694795DC-560D-4C7A-A3DF-B17C59377DF7",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "vendorId",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "getAPAccountBalance",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "AP aging",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "acumatica",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Get the AP balance",
        "nextElementIds": [
          "D8A1D042-CBD5-4558-A5E9-19F0B55BFDE5"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "notes": "Retrieves a list of bills from Acumatica. Use the optional OData filter to narrow results by status, vendor, date range, or other fields. Useful for confirming creates worked or browsing all AP bills.",
          "elementId": "EXTENSION:::SHARED:::default:::acumatica:::listBills",
          "isFirstElement": false,
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "List open bills Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::acumatica:::listBills",
          "legacyElementId": "JS###v1###AcumaticaService###listBills",
          "methodName": "listBills",
          "position": {
            "x": 111,
            "y": 175
          }
        },
        "flowElementId": "5C526586-60C4-4B9C-B18A-CF79172930B7",
        "groupId": null,
        "id": "D8A1D042-CBD5-4558-A5E9-19F0B55BFDE5",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "filter",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": "Status eq 'Open' and Type eq 'Bill'"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "select",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": "ReferenceNbr,Vendor,VendorRef,DueDate,Balance,Amount"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "top",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "listBills",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Open bills",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "acumatica",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "List open bills",
        "nextElementIds": [
          "03F5E517-63D3-4B90-A6A6-579D602C0F00"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      }
    ],
    "firstElementId": "694795DC-560D-4C7A-A3DF-B17C59377DF7",
    "groups": [],
    "id": "1687C5B7-397A-4B9B-9BB2-5E39444C4203",
    "metaInfo": {
      "clientValidationState": {
        "errorMessage": null,
        "valid": true
      },
      "errorMessage": null,
      "executionStaticData": [],
      "initialData": null,
      "initialDataDefaultValues": {},
      "ownerFlowVersionId": null,
      "schedule": null,
      "sharedMemory": {
        "anchor": {
          "missingAnchorPolicy": null,
          "path": null,
          "type": "FLOW_MEMORY"
        },
        "expirationInSec": null
      },
      "wasLive": false
    }
  },
  "slaCalendars": [],
  "slaGoals": [],
  "subFlows": [],
  "exportDate": "2026-11-17T05:53:03.112Z"
}
