{
  "apiVersion": 56,
  "label": "Credits — Stamp Approvers on Retry (NeedsTriage → NotSubmitted)",
  "description": "Companion to Credits_Stamp_Approvers. When sales ops fixes a Region_All__c data gap and the AE (or ops) flips Approval_Status from 'NeedsTriage' back to 'NotSubmitted' to retry, this Flow re-runs the same Region_All__c lookup and re-stamps the three approver User-lookup fields. Without this Flow, NeedsTriage records would remain with NULL approver fields after retry, and AE clicking Submit would hit the engine's submittedByID fallback (approval_service.go:318) — submitter becomes own approver. Trigger filter `Approval_Status__c IsChanged AND EqualTo 'NotSubmitted'` also covers the rare Pending/Approved/Rejected → NotSubmitted manual transitions (e.g., post-Recall); re-stamping is idempotent. See proposal §7.",
  "processType": "AutoLaunchedFlow",
  "status": "Active",
  "start": {
    "object": "Credits__c",
    "triggerType": "RecordBeforeSave",
    "recordTriggerType": "Update",
    "filterLogic": "and",
    "filters": [
      {"field": "Approval_Status__c", "operator": "IsChanged", "value": {"booleanValue": true}},
      {"field": "Approval_Status__c", "operator": "EqualTo", "value": {"stringValue": "NotSubmitted"}}
    ],
    "connector": {"targetReference": "Check_Account_Present"}
  },
  "recordLookups": [
    {
      "name": "Get_Account",
      "label": "Get Account for Region",
      "locationX": 200,
      "locationY": 150,
      "object": "Account",
      "filterLogic": "and",
      "filters": [
        {"field": "Id", "operator": "EqualTo", "value": {"elementReference": "$Record.Account__c"}}
      ],
      "getFirstRecordOnly": true,
      "storeOutputAutomatically": true,
      "assignNullValuesIfNoRecordsFound": false,
      "connector": {"targetReference": "Get_Region_Approvers"}
    },
    {
      "name": "Get_Region_Approvers",
      "label": "Get Region Approvers",
      "locationX": 200,
      "locationY": 250,
      "object": "Region_All__c",
      "filterLogic": "and",
      "filters": [
        {"field": "Region__c", "operator": "EqualTo", "value": {"elementReference": "Get_Account.Region__c"}}
      ],
      "getFirstRecordOnly": true,
      "storeOutputAutomatically": true,
      "assignNullValuesIfNoRecordsFound": false,
      "connector": {"targetReference": "Check_Approvers_Found"}
    }
  ],
  "decisions": [
    {
      "name": "Check_Account_Present",
      "label": "Account linked? (defensive guard)",
      "locationX": 200,
      "locationY": 50,
      "rules": [
        {
          "name": "account_present",
          "label": "Yes — look up region approvers",
          "conditionLogic": "and",
          "conditions": [
            {"leftValueReference": "$Record.Account__c", "operator": "IsNull", "rightValue": {"booleanValue": false}}
          ],
          "connector": {"targetReference": "Get_Account"}
        }
      ],
      "defaultConnectorLabel": "No — terminate"
    },
    {
      "name": "Check_Approvers_Found",
      "label": "Check All Three Approvers Found On Retry",
      "locationX": 200,
      "locationY": 350,
      "rules": [
        {
          "name": "all_approvers_present",
          "label": "All approvers present",
          "conditionLogic": "and",
          "conditions": [
            {"leftValueReference": "Get_Region_Approvers", "operator": "IsNull", "rightValue": {"booleanValue": false}},
            {"leftValueReference": "Get_Region_Approvers.Region_Pre_Sales_Manager__c", "operator": "IsNull", "rightValue": {"booleanValue": false}},
            {"leftValueReference": "Get_Region_Approvers.Regional_Finance__c", "operator": "IsNull", "rightValue": {"booleanValue": false}},
            {"leftValueReference": "Get_Region_Approvers.Region_BG_Leader__c", "operator": "IsNull", "rightValue": {"booleanValue": false}}
          ],
          "connector": {"targetReference": "Stamp_Approvers"}
        }
      ],
      "defaultConnector": {"targetReference": "Route_Back_To_NeedsTriage"},
      "defaultConnectorLabel": "Still missing — bounce back to triage"
    }
  ],
  "assignments": [
    {
      "name": "Stamp_Approvers",
      "label": "Stamp Three Approver User-Lookup Fields (Retry)",
      "locationX": 100,
      "locationY": 450,
      "assignmentItems": [
        {"assignToReference": "$Record.Presales_Manager_User__c", "operator": "Assign", "value": {"elementReference": "Get_Region_Approvers.Region_Pre_Sales_Manager__c"}},
        {"assignToReference": "$Record.Finance_Approver_User__c", "operator": "Assign", "value": {"elementReference": "Get_Region_Approvers.Regional_Finance__c"}},
        {"assignToReference": "$Record.BG_Leader_User__c", "operator": "Assign", "value": {"elementReference": "Get_Region_Approvers.Region_BG_Leader__c"}},
        {"assignToReference": "$Record.Regional_Ops_User__c", "operator": "Assign", "value": {"elementReference": "Get_Region_Approvers.Region_Ops__c"}}
      ]
    },
    {
      "name": "Route_Back_To_NeedsTriage",
      "label": "Region_All__c Still Incomplete — Bounce Back",
      "locationX": 300,
      "locationY": 450,
      "assignmentItems": [
        {"assignToReference": "$Record.Approval_Status__c", "operator": "Assign", "value": {"stringValue": "NeedsTriage"}}
      ]
    }
  ]
}
