{
  "apiVersion": 56,
  "label": "Order — Default PingCAP RevRec Entity from Contracting Entity",
  "description": "Before-save default for PingCAP_RevRec_Entity__c, mirroring the precedence of the Order.PingCAP_Contracting_Entity__c active formula (which cannot be read pre-insert): prefer Opportunity.PingCAP_Contracting_Entity_EMEA_only__c when set (its picklist values are a subset of the RevRec picklist), else Account.PingCAP_Contracting_Entity__c when it is one of the three RevRec entities. The Beijing contracting entity has no RevRec counterpart and is left blank for finance; RevRec_Entity_Required_When_Activated then blocks activation until finance picks one. Runs on CreateAndUpdate so blank orders self-heal on their next edit; note this also means clearing the field on a derivable order re-derives the default in the same save — blank is not a persistable state when a default exists. Only fills blanks — a different explicit value is never overwritten (cross-entity revenue recognition is a real business case). COUPLING: the entity strings in Check_EMEA_Override and Check_Contracting_Maps_To_RevRec are membership allowlists that must stay in sync with the Order.PingCAP_RevRec_Entity__c picklist options (objects/Order.json); values outside the allowlists (new legal entities, the Beijing contracting entity) safely fall through to blank + the activation VR, but adding a RevRec entity requires updating both decisions (and the order-revrec-entity-default-api inspection case's step-1 regex) or orders for it will default blank.",
  "processType": "AutoLaunchedFlow",
  "status": "Active",
  "start": {
    "object": "Order",
    "triggerType": "RecordBeforeSave",
    "recordTriggerType": "CreateAndUpdate",
    "filterLogic": "and",
    "filters": [
      {"field": "PingCAP_RevRec_Entity__c", "operator": "IsNull", "value": {"booleanValue": true}}
    ],
    "connector": {"targetReference": "Check_Opportunity_Present"}
  },
  "recordLookups": [
    {
      "name": "Get_Opportunity",
      "label": "Get Opportunity for EMEA Contracting Override",
      "locationX": 100,
      "locationY": 200,
      "object": "Opportunity",
      "filterLogic": "and",
      "filters": [
        {"field": "Id", "operator": "EqualTo", "value": {"elementReference": "$Record.OpportunityId"}}
      ],
      "getFirstRecordOnly": true,
      "storeOutputAutomatically": true,
      "assignNullValuesIfNoRecordsFound": false,
      "connector": {"targetReference": "Check_EMEA_Override"}
    },
    {
      "name": "Get_Account",
      "label": "Get Account Contracting Entity",
      "locationX": 300,
      "locationY": 300,
      "object": "Account",
      "filterLogic": "and",
      "filters": [
        {"field": "Id", "operator": "EqualTo", "value": {"elementReference": "$Record.AccountId"}}
      ],
      "getFirstRecordOnly": true,
      "storeOutputAutomatically": true,
      "assignNullValuesIfNoRecordsFound": false,
      "connector": {"targetReference": "Check_Contracting_Maps_To_RevRec"}
    }
  ],
  "decisions": [
    {
      "name": "Check_Opportunity_Present",
      "label": "Opportunity linked?",
      "locationX": 200,
      "locationY": 100,
      "rules": [
        {
          "name": "opportunity_present",
          "label": "Yes — check EMEA contracting override",
          "conditionLogic": "and",
          "conditions": [
            {"leftValueReference": "$Record.OpportunityId", "operator": "IsNull", "rightValue": {"booleanValue": false}}
          ],
          "connector": {"targetReference": "Get_Opportunity"}
        }
      ],
      "defaultConnector": {"targetReference": "Check_Account_Present"},
      "defaultConnectorLabel": "No — derive from Account"
    },
    {
      "name": "Check_EMEA_Override",
      "label": "EMEA contracting override set?",
      "locationX": 100,
      "locationY": 300,
      "rules": [
        {
          "name": "emea_override_is_revrec_entity",
          "label": "Yes — override is one of the RevRec entities, stamp it",
          "conditionLogic": "or",
          "conditions": [
            {"leftValueReference": "Get_Opportunity.PingCAP_Contracting_Entity_EMEA_only__c", "operator": "EqualTo", "rightValue": {"stringValue": "PingCAP Pte. Ltd."}},
            {"leftValueReference": "Get_Opportunity.PingCAP_Contracting_Entity_EMEA_only__c", "operator": "EqualTo", "rightValue": {"stringValue": "PingCAP (US), Inc."}}
          ],
          "connector": {"targetReference": "Stamp_From_EMEA_Override"}
        }
      ],
      "defaultConnector": {"targetReference": "Check_Account_Present"},
      "defaultConnectorLabel": "No — derive from Account"
    },
    {
      "name": "Check_Account_Present",
      "label": "Account linked? (defensive guard)",
      "locationX": 300,
      "locationY": 200,
      "rules": [
        {
          "name": "account_present",
          "label": "Yes — fetch Account contracting entity",
          "conditionLogic": "and",
          "conditions": [
            {"leftValueReference": "$Record.AccountId", "operator": "IsNull", "rightValue": {"booleanValue": false}}
          ],
          "connector": {"targetReference": "Get_Account"}
        }
      ],
      "defaultConnectorLabel": "No — leave blank"
    },
    {
      "name": "Check_Contracting_Maps_To_RevRec",
      "label": "Contracting entity is one of the three RevRec entities?",
      "locationX": 300,
      "locationY": 400,
      "rules": [
        {
          "name": "contracting_maps",
          "label": "Yes — stamp same-name RevRec entity",
          "conditionLogic": "or",
          "conditions": [
            {"leftValueReference": "Get_Account.PingCAP_Contracting_Entity__c", "operator": "EqualTo", "rightValue": {"stringValue": "PingCAP Kabushiki-Kaisha"}},
            {"leftValueReference": "Get_Account.PingCAP_Contracting_Entity__c", "operator": "EqualTo", "rightValue": {"stringValue": "PingCAP Pte. Ltd."}},
            {"leftValueReference": "Get_Account.PingCAP_Contracting_Entity__c", "operator": "EqualTo", "rightValue": {"stringValue": "PingCAP (US), Inc."}}
          ],
          "connector": {"targetReference": "Stamp_From_Account"}
        }
      ],
      "defaultConnectorLabel": "No (Beijing entity or blank) — leave blank for finance"
    }
  ],
  "assignments": [
    {
      "name": "Stamp_From_EMEA_Override",
      "label": "Stamp RevRec Entity = Opportunity EMEA contracting override",
      "locationX": 100,
      "locationY": 400,
      "assignmentItems": [
        {"assignToReference": "$Record.PingCAP_RevRec_Entity__c", "operator": "Assign", "value": {"elementReference": "Get_Opportunity.PingCAP_Contracting_Entity_EMEA_only__c"}}
      ]
    },
    {
      "name": "Stamp_From_Account",
      "label": "Stamp RevRec Entity = Account contracting entity",
      "locationX": 300,
      "locationY": 500,
      "assignmentItems": [
        {"assignToReference": "$Record.PingCAP_RevRec_Entity__c", "operator": "Assign", "value": {"elementReference": "Get_Account.PingCAP_Contracting_Entity__c"}}
      ]
    }
  ]
}
