{
  "apiVersion": 65,
  "label": "Opportunity Rate from Dated Conversion",
  "description": "Stamps Opportunity.Rate__c from the Dated_Conversion_Rate__c period covering CloseDate, before every Opportunity save \u2014 a faithful port of the source org's before-save Apex (GetOppRateTriggerHandler): USD short-circuits to 1, other currencies match the half-open period [Start_Date__c, Next_Start_Date__c), no matching period or currency leaves the field untouched, and CloseDate moves re-stamp on the next save. When periods overlap (an appended month whose predecessor was not closed), the newest applicable Start_Date__c wins deterministically, so operator error in the hand-maintained table cannot make the stamped rate order-dependent. Before-save with direct $Record assignments (the Std_OpportunityStageDerivedFields pattern) rather than after-save + recordUpdate: an after-save update inside the record.created chain is silently lost on this platform (the update targets a row the flow transaction cannot yet see), and before-save needs no self-retrigger guard. Part of #3873: without Rate__c, Exchange_Rate__c and TCV_Amount_USD__c stay blank on natively created opportunities and every discount-approval gate reads N.",
  "processType": "AutoLaunchedFlow",
  "status": "Active",
  "start": {
    "locationX": 0,
    "locationY": 0,
    "connector": {
      "targetReference": "Currency_Branch"
    },
    "object": "Opportunity",
    "recordTriggerType": "CreateAndUpdate",
    "triggerType": "RecordBeforeSave"
  },
  "decisions": [
    {
      "name": "Currency_Branch",
      "label": "Currency Branch",
      "locationX": 0,
      "locationY": 0,
      "defaultConnector": {
        "targetReference": "Get_Rates"
      },
      "defaultConnectorLabel": "Other Currency",
      "rules": [
        {
          "name": "Is_USD",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$Record.CurrencyIsoCode",
              "operator": "EqualTo",
              "rightValue": {
                "stringValue": "USD"
              }
            }
          ],
          "connector": {
            "targetReference": "Assign_USD_Rate"
          },
          "label": "Is USD"
        }
      ]
    },
    {
      "name": "Period_Matches",
      "label": "Period Matches",
      "locationX": 0,
      "locationY": 0,
      "defaultConnector": {
        "targetReference": "Loop_Rates"
      },
      "defaultConnectorLabel": "Outside Period",
      "rules": [
        {
          "name": "In_Period",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$Record.CloseDate",
              "operator": "GreaterThanOrEqualTo",
              "rightValue": {
                "elementReference": "Loop_Rates.Start_Date__c"
              }
            },
            {
              "leftValueReference": "$Record.CloseDate",
              "operator": "LessThan",
              "rightValue": {
                "elementReference": "Loop_Rates.Next_Start_Date__c"
              }
            }
          ],
          "connector": {
            "targetReference": "Newer_Than_Best"
          },
          "label": "In Period"
        }
      ]
    },
    {
      "name": "Newer_Than_Best",
      "label": "Newer Than Best",
      "locationX": 0,
      "locationY": 0,
      "defaultConnector": {
        "targetReference": "Loop_Rates"
      },
      "defaultConnectorLabel": "Older Period",
      "rules": [
        {
          "name": "First_Match",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "BestStart",
              "operator": "IsNull",
              "rightValue": {
                "booleanValue": true
              }
            }
          ],
          "connector": {
            "targetReference": "Assign_Matched_Rate"
          },
          "label": "First Match"
        },
        {
          "name": "Newer",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "Loop_Rates.Start_Date__c",
              "operator": "GreaterThan",
              "rightValue": {
                "elementReference": "BestStart"
              }
            }
          ],
          "connector": {
            "targetReference": "Assign_Matched_Rate"
          },
          "label": "Newer"
        }
      ]
    }
  ],
  "recordLookups": [
    {
      "name": "Get_Rates",
      "label": "Get Rates for Currency",
      "locationX": 0,
      "locationY": 0,
      "assignNullValuesIfNoRecordsFound": false,
      "connector": {
        "targetReference": "Loop_Rates"
      },
      "filterLogic": "and",
      "filters": [
        {
          "field": "Iso_Code__c",
          "operator": "EqualTo",
          "value": {
            "elementReference": "$Record.CurrencyIsoCode"
          }
        }
      ],
      "getFirstRecordOnly": false,
      "object": "Dated_Conversion_Rate__c",
      "queriedFields": [
        "Id",
        "Iso_Code__c",
        "Conversion_Rate__c",
        "Start_Date__c",
        "Next_Start_Date__c"
      ],
      "storeOutputAutomatically": true
    }
  ],
  "loops": [
    {
      "name": "Loop_Rates",
      "label": "Loop Rate Periods",
      "locationX": 0,
      "locationY": 0,
      "collectionReference": "Get_Rates",
      "iterationOrder": "Asc",
      "nextValueConnector": {
        "targetReference": "Period_Matches"
      }
    }
  ],
  "assignments": [
    {
      "name": "Assign_USD_Rate",
      "label": "Assign USD Rate",
      "locationX": 0,
      "locationY": 0,
      "assignmentItems": [
        {
          "assignToReference": "$Record.Rate__c",
          "operator": "Assign",
          "value": {
            "numberValue": 1
          }
        }
      ]
    },
    {
      "name": "Assign_Matched_Rate",
      "label": "Assign Matched Rate",
      "locationX": 0,
      "locationY": 0,
      "assignmentItems": [
        {
          "assignToReference": "$Record.Rate__c",
          "operator": "Assign",
          "value": {
            "elementReference": "Loop_Rates.Conversion_Rate__c"
          }
        },
        {
          "assignToReference": "BestStart",
          "operator": "Assign",
          "value": {
            "elementReference": "Loop_Rates.Start_Date__c"
          }
        }
      ],
      "connector": {
        "targetReference": "Loop_Rates"
      }
    }
  ],
  "variables": [
    {
      "name": "BestStart",
      "dataType": "Date"
    }
  ]
}
