{
  "apiVersion": 63,
  "status": "Active",
  "label": "HubSpot Contact Merge Reconcile",
  "description": "Reconciles a HubSpot contact merge into one active NexusCRM person, retaining retired HubSpot ids as canonical aliases before deleting or rekeying local records.",
  "runAtomically": true,
  "start": {
    "locationX": 40,
    "locationY": 0,
    "connector": {
      "targetReference": "DecidePrimaryMergeAlias"
    }
  },
  "variables": [
    {
      "name": "payload",
      "dataType": "Any",
      "isInput": true
    },
    {
      "name": "record",
      "dataType": "Any",
      "isInput": true
    },
    {
      "name": "sourceID",
      "dataType": "String",
      "isInput": true
    },
    {
      "name": "survivorLeadId",
      "dataType": "String"
    },
    {
      "name": "survivorContactId",
      "dataType": "String"
    },
    {
      "name": "currentMergedHubSpotId",
      "dataType": "String"
    }
  ],
  "recordLookups": [
    {
      "name": "FindLeadByCanonicalHubSpotId",
      "label": "Find active Lead already bound to the canonical HubSpot id",
      "locationX": 40,
      "locationY": 120,
      "object": "Lead",
      "filterLogic": "and",
      "filters": [
        {
          "field": "HubSpot_Id__c",
          "operator": "EqualTo",
          "value": {
            "elementReference": "effectiveCanonicalHubSpotId"
          }
        },
        {
          "field": "IsConverted",
          "operator": "NotEqualTo",
          "value": true
        }
      ],
      "outputReference": "$canonicalLead",
      "getFirstRecordOnly": true,
      "connector": {
        "targetReference": "FindContactByCanonicalHubSpotId"
      }
    },
    {
      "name": "FindContactByCanonicalHubSpotId",
      "label": "Find Contact already bound to the canonical HubSpot id",
      "locationX": 220,
      "locationY": 120,
      "object": "Contact",
      "filterLogic": "and",
      "filters": [
        {
          "field": "HubSpot_Id__c",
          "operator": "EqualTo",
          "value": {
            "elementReference": "effectiveCanonicalHubSpotId"
          }
        }
      ],
      "outputReference": "$canonicalContact",
      "getFirstRecordOnly": true,
      "connector": {
        "targetReference": "HandleCanonicalPerson"
      }
    },
    {
      "name": "FindLeadByPrimaryHubSpotId",
      "label": "Find active Lead still bound to the primary legacy HubSpot id",
      "locationX": 400,
      "locationY": 120,
      "object": "Lead",
      "filterLogic": "and",
      "filters": [
        {
          "field": "HubSpot_Id__c",
          "operator": "EqualTo",
          "value": {
            "elementReference": "effectivePrimaryHubSpotId"
          }
        },
        {
          "field": "IsConverted",
          "operator": "NotEqualTo",
          "value": true
        }
      ],
      "outputReference": "$primaryLead",
      "getFirstRecordOnly": true,
      "connector": {
        "targetReference": "FindContactByPrimaryHubSpotId"
      }
    },
    {
      "name": "FindContactByPrimaryHubSpotId",
      "label": "Find Contact still bound to the primary legacy HubSpot id",
      "locationX": 580,
      "locationY": 120,
      "object": "Contact",
      "filterLogic": "and",
      "filters": [
        {
          "field": "HubSpot_Id__c",
          "operator": "EqualTo",
          "value": {
            "elementReference": "effectivePrimaryHubSpotId"
          }
        }
      ],
      "outputReference": "$primaryContact",
      "getFirstRecordOnly": true,
      "connector": {
        "targetReference": "HandlePrimaryPerson"
      }
    },
    {
      "name": "FindLeadByMergedHubSpotId",
      "label": "Find active Lead by merged-away HubSpot id",
      "locationX": 760,
      "locationY": 360,
      "object": "Lead",
      "filterLogic": "and",
      "filters": [
        {
          "field": "HubSpot_Id__c",
          "operator": "EqualTo",
          "value": {
            "elementReference": "currentMergedHubSpotId"
          }
        },
        {
          "field": "IsConverted",
          "operator": "NotEqualTo",
          "value": true
        }
      ],
      "outputReference": "$mergedLead",
      "getFirstRecordOnly": true,
      "connector": {
        "targetReference": "FindContactByMergedHubSpotId"
      }
    },
    {
      "name": "FindContactByMergedHubSpotId",
      "label": "Find Contact by merged-away HubSpot id",
      "locationX": 940,
      "locationY": 360,
      "object": "Contact",
      "filterLogic": "and",
      "filters": [
        {
          "field": "HubSpot_Id__c",
          "operator": "EqualTo",
          "value": {
            "elementReference": "currentMergedHubSpotId"
          }
        }
      ],
      "outputReference": "$mergedContact",
      "getFirstRecordOnly": true,
      "connector": {
        "targetReference": "HandleMergedPerson"
      }
    },
    {
      "name": "FindHubSpotContactMergeAlias",
      "label": "Find retained alias for the current merged-away HubSpot id",
      "locationX": 760,
      "locationY": 300,
      "object": "HubSpotContactMergeAlias__c",
      "filterLogic": "and",
      "filters": [
        {
          "field": "LegacyHubSpotId__c",
          "operator": "EqualTo",
          "value": {
            "elementReference": "currentMergedHubSpotId"
          }
        }
      ],
      "outputReference": "$hubSpotContactMergeAlias",
      "getFirstRecordOnly": true,
      "assignNullValuesIfNoRecordsFound": true,
      "coalesceInFlight": true,
      "connector": {
        "targetReference": "DecideHubSpotContactMergeAliasWrite"
      }
    }
  ],
  "decisions": [
    {
      "name": "DecidePrimaryMergeAlias",
      "label": "Does the primary HubSpot id become a retained merge alias?",
      "locationX": 40,
      "locationY": 60,
      "rules": [
        {
          "name": "PrimaryIdDiffersFromCanonicalId",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "effectivePrimaryHubSpotId",
              "operator": "NotEqualTo",
              "rightValue": {
                "elementReference": "effectiveCanonicalHubSpotId"
              }
            }
          ],
          "connector": {
            "targetReference": "PreparePrimaryMergeAlias"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "FindLeadByCanonicalHubSpotId"
      }
    },
    {
      "name": "DecideHubSpotContactMergeAliasWrite",
      "label": "Create or refresh the retained HubSpot merge alias",
      "locationX": 940,
      "locationY": 300,
      "rules": [
        {
          "name": "MergeAliasExists",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$hubSpotContactMergeAlias.Id",
              "operator": "IsNotBlank"
            }
          ],
          "connector": {
            "targetReference": "UpdateHubSpotContactMergeAlias"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "CreateHubSpotContactMergeAlias"
      }
    },
    {
      "name": "ContinueAfterHubSpotContactMergeAliasWrite",
      "label": "Continue reconciliation after retaining the HubSpot merge alias",
      "locationX": 1100,
      "locationY": 300,
      "rules": [
        {
          "name": "PrimaryAliasRetained",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "currentMergedHubSpotId",
              "operator": "EqualTo",
              "rightValue": {
                "elementReference": "effectivePrimaryHubSpotId"
              }
            }
          ],
          "connector": {
            "targetReference": "FindLeadByCanonicalHubSpotId"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "FindLeadByMergedHubSpotId"
      }
    },
    {
      "name": "HandleCanonicalPerson",
      "label": "Choose a canonical active person when one is already re-keyed",
      "locationX": 220,
      "locationY": 240,
      "rules": [
        {
          "name": "CanonicalPersonAmbiguous",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$canonicalLead.Id",
              "operator": "IsNotBlank"
            },
            {
              "leftValueReference": "$canonicalContact.Id",
              "operator": "IsNotBlank"
            }
          ],
          "connector": {
            "targetReference": "FailAmbiguousMergePerson"
          }
        },
        {
          "name": "CanonicalLeadFound",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$canonicalLead.Id",
              "operator": "IsNotBlank"
            },
            {
              "leftValueReference": "$canonicalContact.Id",
              "operator": "IsBlank"
            }
          ],
          "connector": {
            "targetReference": "UseCanonicalLeadAsSurvivor"
          }
        },
        {
          "name": "CanonicalContactFound",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$canonicalContact.Id",
              "operator": "IsNotBlank"
            },
            {
              "leftValueReference": "$canonicalLead.Id",
              "operator": "IsBlank"
            }
          ],
          "connector": {
            "targetReference": "UseCanonicalContactAsSurvivor"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "FindLeadByPrimaryHubSpotId"
      }
    },
    {
      "name": "HandlePrimaryPerson",
      "label": "Keep, delete, or skip the primary legacy person mapping",
      "locationX": 580,
      "locationY": 240,
      "rules": [
        {
          "name": "PrimaryPersonAmbiguous",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$primaryLead.Id",
              "operator": "IsNotBlank"
            },
            {
              "leftValueReference": "$primaryContact.Id",
              "operator": "IsNotBlank"
            }
          ],
          "connector": {
            "targetReference": "FailAmbiguousMergePerson"
          }
        },
        {
          "name": "PrimaryPersonMissing",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$primaryLead.Id",
              "operator": "IsBlank"
            },
            {
              "leftValueReference": "$primaryContact.Id",
              "operator": "IsBlank"
            }
          ],
          "connector": {
            "targetReference": "LoopMergedObjectIds"
          }
        },
        {
          "name": "PrimaryLeadBecomesSurvivor",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$primaryLead.Id",
              "operator": "IsNotBlank"
            },
            {
              "leftValueReference": "$primaryContact.Id",
              "operator": "IsBlank"
            },
            {
              "leftValueReference": "survivorLeadId",
              "operator": "IsBlank"
            },
            {
              "leftValueReference": "survivorContactId",
              "operator": "IsBlank"
            }
          ],
          "connector": {
            "targetReference": "UsePrimaryLeadAsSurvivor"
          }
        },
        {
          "name": "PrimaryContactBecomesSurvivor",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$primaryContact.Id",
              "operator": "IsNotBlank"
            },
            {
              "leftValueReference": "$primaryLead.Id",
              "operator": "IsBlank"
            },
            {
              "leftValueReference": "survivorLeadId",
              "operator": "IsBlank"
            },
            {
              "leftValueReference": "survivorContactId",
              "operator": "IsBlank"
            }
          ],
          "connector": {
            "targetReference": "UsePrimaryContactAsSurvivor"
          }
        },
        {
          "name": "PrimaryLeadAlreadySurvivor",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$primaryLead.Id",
              "operator": "IsNotBlank"
            },
            {
              "leftValueReference": "$primaryContact.Id",
              "operator": "IsBlank"
            },
            {
              "leftValueReference": "$primaryLead.Id",
              "operator": "EqualTo",
              "rightValue": {
                "elementReference": "survivorLeadId"
              }
            }
          ],
          "connector": {
            "targetReference": "LoopMergedObjectIds"
          }
        },
        {
          "name": "PrimaryContactAlreadySurvivor",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$primaryContact.Id",
              "operator": "IsNotBlank"
            },
            {
              "leftValueReference": "$primaryLead.Id",
              "operator": "IsBlank"
            },
            {
              "leftValueReference": "$primaryContact.Id",
              "operator": "EqualTo",
              "rightValue": {
                "elementReference": "survivorContactId"
              }
            }
          ],
          "connector": {
            "targetReference": "LoopMergedObjectIds"
          }
        },
        {
          "name": "PrimaryLeadAlias",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$primaryLead.Id",
              "operator": "IsNotBlank"
            },
            {
              "leftValueReference": "$primaryContact.Id",
              "operator": "IsBlank"
            }
          ],
          "connector": {
            "targetReference": "DeletePrimaryLeadAlias"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "DeletePrimaryContactAlias"
      }
    },
    {
      "name": "HandleMergedPerson",
      "label": "Delete merged-away aliases after selecting a survivor",
      "locationX": 940,
      "locationY": 480,
      "rules": [
        {
          "name": "MergedPersonAmbiguous",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$mergedLead.Id",
              "operator": "IsNotBlank"
            },
            {
              "leftValueReference": "$mergedContact.Id",
              "operator": "IsNotBlank"
            }
          ],
          "connector": {
            "targetReference": "FailAmbiguousMergePerson"
          }
        },
        {
          "name": "MergedPersonMissing",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$mergedLead.Id",
              "operator": "IsBlank"
            },
            {
              "leftValueReference": "$mergedContact.Id",
              "operator": "IsBlank"
            }
          ],
          "connector": {
            "targetReference": "LoopMergedObjectIds"
          }
        },
        {
          "name": "MergedLeadBecomesSurvivor",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$mergedLead.Id",
              "operator": "IsNotBlank"
            },
            {
              "leftValueReference": "$mergedContact.Id",
              "operator": "IsBlank"
            },
            {
              "leftValueReference": "survivorLeadId",
              "operator": "IsBlank"
            },
            {
              "leftValueReference": "survivorContactId",
              "operator": "IsBlank"
            }
          ],
          "connector": {
            "targetReference": "UseMergedLeadAsSurvivor"
          }
        },
        {
          "name": "MergedContactBecomesSurvivor",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$mergedContact.Id",
              "operator": "IsNotBlank"
            },
            {
              "leftValueReference": "$mergedLead.Id",
              "operator": "IsBlank"
            },
            {
              "leftValueReference": "survivorLeadId",
              "operator": "IsBlank"
            },
            {
              "leftValueReference": "survivorContactId",
              "operator": "IsBlank"
            }
          ],
          "connector": {
            "targetReference": "UseMergedContactAsSurvivor"
          }
        },
        {
          "name": "MergedLeadAlreadySurvivor",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$mergedLead.Id",
              "operator": "IsNotBlank"
            },
            {
              "leftValueReference": "$mergedContact.Id",
              "operator": "IsBlank"
            },
            {
              "leftValueReference": "$mergedLead.Id",
              "operator": "EqualTo",
              "rightValue": {
                "elementReference": "survivorLeadId"
              }
            }
          ],
          "connector": {
            "targetReference": "LoopMergedObjectIds"
          }
        },
        {
          "name": "MergedContactAlreadySurvivor",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$mergedContact.Id",
              "operator": "IsNotBlank"
            },
            {
              "leftValueReference": "$mergedLead.Id",
              "operator": "IsBlank"
            },
            {
              "leftValueReference": "$mergedContact.Id",
              "operator": "EqualTo",
              "rightValue": {
                "elementReference": "survivorContactId"
              }
            }
          ],
          "connector": {
            "targetReference": "LoopMergedObjectIds"
          }
        },
        {
          "name": "MergedLeadAlias",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$mergedLead.Id",
              "operator": "IsNotBlank"
            },
            {
              "leftValueReference": "$mergedContact.Id",
              "operator": "IsBlank"
            }
          ],
          "connector": {
            "targetReference": "DeleteMergedLeadAlias"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "DeleteMergedContactAlias"
      }
    },
    {
      "name": "FinalizeMerge",
      "label": "Retry until a local survivor exists; otherwise re-key the survivor to the canonical id",
      "locationX": 940,
      "locationY": 720,
      "rules": [
        {
          "name": "NoLocalPersonYet",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "survivorLeadId",
              "operator": "IsBlank"
            },
            {
              "leftValueReference": "survivorContactId",
              "operator": "IsBlank"
            }
          ],
          "connector": {
            "targetReference": "RetryUntilLocalPersonLands"
          }
        },
        {
          "name": "LeadSurvivorChosen",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "survivorLeadId",
              "operator": "IsNotBlank"
            },
            {
              "leftValueReference": "survivorContactId",
              "operator": "IsBlank"
            }
          ],
          "connector": {
            "targetReference": "RekeySurvivorLeadToCanonicalId"
          }
        },
        {
          "name": "ContactSurvivorChosen",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "survivorContactId",
              "operator": "IsNotBlank"
            },
            {
              "leftValueReference": "survivorLeadId",
              "operator": "IsBlank"
            }
          ],
          "connector": {
            "targetReference": "RekeySurvivorContactToCanonicalId"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "FailAmbiguousMergePerson"
      }
    }
  ],
  "formulas": [
    {
      "name": "effectiveCanonicalHubSpotId",
      "dataType": "String",
      "expression": "TEXT(BLANKVALUE(payload.newObjectId, BLANKVALUE(payload.primaryObjectId, sourceID)))"
    },
    {
      "name": "effectivePrimaryHubSpotId",
      "dataType": "String",
      "expression": "TEXT(BLANKVALUE(payload.primaryObjectId, sourceID))"
    }
  ],
  "assignments": [
    {
      "name": "PreparePrimaryMergeAlias",
      "label": "Retain the primary HubSpot id before it is re-keyed",
      "locationX": 220,
      "locationY": 60,
      "assignmentItems": [
        {
          "assignToReference": "currentMergedHubSpotId",
          "operator": "Assign",
          "value": {
            "elementReference": "effectivePrimaryHubSpotId"
          }
        }
      ],
      "connector": {
        "targetReference": "RepointAliasesFromPrimaryHubSpotId"
      }
    },
    {
      "name": "UseCanonicalLeadAsSurvivor",
      "label": "Preserve canonical Lead",
      "locationX": 120,
      "locationY": 360,
      "assignmentItems": [
        {
          "assignToReference": "survivorLeadId",
          "operator": "Assign",
          "value": {
            "elementReference": "$canonicalLead.Id"
          }
        }
      ],
      "connector": {
        "targetReference": "FindLeadByPrimaryHubSpotId"
      }
    },
    {
      "name": "UseCanonicalContactAsSurvivor",
      "label": "Preserve canonical Contact",
      "locationX": 280,
      "locationY": 360,
      "assignmentItems": [
        {
          "assignToReference": "survivorContactId",
          "operator": "Assign",
          "value": {
            "elementReference": "$canonicalContact.Id"
          }
        }
      ],
      "connector": {
        "targetReference": "FindLeadByPrimaryHubSpotId"
      }
    },
    {
      "name": "UsePrimaryLeadAsSurvivor",
      "label": "Preserve primary legacy Lead",
      "locationX": 420,
      "locationY": 360,
      "assignmentItems": [
        {
          "assignToReference": "survivorLeadId",
          "operator": "Assign",
          "value": {
            "elementReference": "$primaryLead.Id"
          }
        }
      ],
      "connector": {
        "targetReference": "LoopMergedObjectIds"
      }
    },
    {
      "name": "UsePrimaryContactAsSurvivor",
      "label": "Preserve primary legacy Contact",
      "locationX": 580,
      "locationY": 360,
      "assignmentItems": [
        {
          "assignToReference": "survivorContactId",
          "operator": "Assign",
          "value": {
            "elementReference": "$primaryContact.Id"
          }
        }
      ],
      "connector": {
        "targetReference": "LoopMergedObjectIds"
      }
    },
    {
      "name": "UseMergedLeadAsSurvivor",
      "label": "Preserve first merged-away Lead when nothing else exists locally",
      "locationX": 860,
      "locationY": 600,
      "assignmentItems": [
        {
          "assignToReference": "survivorLeadId",
          "operator": "Assign",
          "value": {
            "elementReference": "$mergedLead.Id"
          }
        }
      ],
      "connector": {
        "targetReference": "LoopMergedObjectIds"
      }
    },
    {
      "name": "UseMergedContactAsSurvivor",
      "label": "Preserve first merged-away Contact when nothing else exists locally",
      "locationX": 1020,
      "locationY": 600,
      "assignmentItems": [
        {
          "assignToReference": "survivorContactId",
          "operator": "Assign",
          "value": {
            "elementReference": "$mergedContact.Id"
          }
        }
      ],
      "connector": {
        "targetReference": "LoopMergedObjectIds"
      }
    }
  ],
  "loops": [
    {
      "name": "LoopMergedObjectIds",
      "label": "Loop merged-away HubSpot ids",
      "locationX": 760,
      "locationY": 240,
      "collectionReference": "payload.mergedObjectIds",
      "assignNextValueToReference": "currentMergedHubSpotId",
      "nextValueConnector": {
        "targetReference": "RepointAliasesFromMergedHubSpotId"
      },
      "noMoreValuesConnector": {
        "targetReference": "FinalizeMerge"
      }
    }
  ],
  "recordUpdates": [
    {
      "name": "RepointAliasesFromPrimaryHubSpotId",
      "label": "Flatten existing aliases that point to the primary HubSpot id",
      "locationX": 400,
      "locationY": 60,
      "object": "HubSpotContactMergeAlias__c",
      "filterLogic": "and",
      "filters": [
        {
          "field": "CanonicalHubSpotId__c",
          "operator": "EqualTo",
          "value": {
            "elementReference": "effectivePrimaryHubSpotId"
          }
        }
      ],
      "inputAssignments": [
        {
          "field": "CanonicalHubSpotId__c",
          "value": {
            "elementReference": "effectiveCanonicalHubSpotId"
          }
        }
      ],
      "connector": {
        "targetReference": "FindHubSpotContactMergeAlias"
      }
    },
    {
      "name": "RepointAliasesFromMergedHubSpotId",
      "label": "Flatten existing aliases that point to the merged-away HubSpot id",
      "locationX": 760,
      "locationY": 270,
      "object": "HubSpotContactMergeAlias__c",
      "filterLogic": "and",
      "filters": [
        {
          "field": "CanonicalHubSpotId__c",
          "operator": "EqualTo",
          "value": {
            "elementReference": "currentMergedHubSpotId"
          }
        }
      ],
      "inputAssignments": [
        {
          "field": "CanonicalHubSpotId__c",
          "value": {
            "elementReference": "effectiveCanonicalHubSpotId"
          }
        }
      ],
      "connector": {
        "targetReference": "FindHubSpotContactMergeAlias"
      }
    },
    {
      "name": "UpdateHubSpotContactMergeAlias",
      "label": "Refresh retained HubSpot merge alias to the canonical id",
      "locationX": 1020,
      "locationY": 360,
      "object": "HubSpotContactMergeAlias__c",
      "filterLogic": "and",
      "filters": [
        {
          "field": "Id",
          "operator": "EqualTo",
          "value": {
            "elementReference": "$hubSpotContactMergeAlias.Id"
          }
        }
      ],
      "inputAssignments": [
        {
          "field": "CanonicalHubSpotId__c",
          "value": {
            "elementReference": "effectiveCanonicalHubSpotId"
          }
        }
      ],
      "connector": {
        "targetReference": "ContinueAfterHubSpotContactMergeAliasWrite"
      }
    },
    {
      "name": "RekeySurvivorLeadToCanonicalId",
      "label": "Re-key survivor Lead to the canonical HubSpot id",
      "locationX": 860,
      "locationY": 840,
      "object": "Lead",
      "filterLogic": "and",
      "filters": [
        {
          "field": "Id",
          "operator": "EqualTo",
          "value": {
            "elementReference": "survivorLeadId"
          }
        }
      ],
      "inputAssignments": [
        {
          "field": "HubSpot_Id__c",
          "value": {
            "elementReference": "effectiveCanonicalHubSpotId"
          }
        }
      ]
    },
    {
      "name": "RekeySurvivorContactToCanonicalId",
      "label": "Re-key survivor Contact to the canonical HubSpot id",
      "locationX": 1020,
      "locationY": 840,
      "object": "Contact",
      "filterLogic": "and",
      "filters": [
        {
          "field": "Id",
          "operator": "EqualTo",
          "value": {
            "elementReference": "survivorContactId"
          }
        }
      ],
      "inputAssignments": [
        {
          "field": "HubSpot_Id__c",
          "value": {
            "elementReference": "effectiveCanonicalHubSpotId"
          }
        }
      ]
    }
  ],
  "recordCreates": [
    {
      "name": "CreateHubSpotContactMergeAlias",
      "label": "Retain merged-away HubSpot id as a canonical alias",
      "locationX": 1020,
      "locationY": 300,
      "object": "HubSpotContactMergeAlias__c",
      "inputAssignments": [
        {
          "field": "LegacyHubSpotId__c",
          "value": {
            "elementReference": "currentMergedHubSpotId"
          }
        },
        {
          "field": "CanonicalHubSpotId__c",
          "value": {
            "elementReference": "effectiveCanonicalHubSpotId"
          }
        }
      ],
      "connector": {
        "targetReference": "ContinueAfterHubSpotContactMergeAliasWrite"
      }
    }
  ],
  "recordDeletes": [
    {
      "name": "DeletePrimaryLeadAlias",
      "label": "Delete primary legacy Lead alias after merge",
      "locationX": 500,
      "locationY": 480,
      "object": "Lead",
      "inputReference": "$primaryLead",
      "connector": {
        "targetReference": "LoopMergedObjectIds"
      }
    },
    {
      "name": "DeletePrimaryContactAlias",
      "label": "Delete primary legacy Contact alias after merge",
      "locationX": 660,
      "locationY": 480,
      "object": "Contact",
      "inputReference": "$primaryContact",
      "connector": {
        "targetReference": "LoopMergedObjectIds"
      }
    },
    {
      "name": "DeleteMergedLeadAlias",
      "label": "Delete merged-away Lead alias after merge",
      "locationX": 860,
      "locationY": 600,
      "object": "Lead",
      "inputReference": "$mergedLead",
      "connector": {
        "targetReference": "LoopMergedObjectIds"
      }
    },
    {
      "name": "DeleteMergedContactAlias",
      "label": "Delete merged-away Contact alias after merge",
      "locationX": 1020,
      "locationY": 600,
      "object": "Contact",
      "inputReference": "$mergedContact",
      "connector": {
        "targetReference": "LoopMergedObjectIds"
      }
    }
  ],
  "actionCalls": [
    {
      "name": "RetryUntilLocalPersonLands",
      "label": "Retry until a local active person exists for the merged HubSpot contact cluster",
      "locationX": 1180,
      "locationY": 720,
      "actionName": "setRetriable",
      "actionType": "setRetriable",
      "inputParameters": [
        {
          "name": "reason",
          "value": {
            "stringValue": "contact merge arrived before any local active Lead or Contact in the merged HubSpot id cluster existed; retrying until a survivor lands locally"
          }
        }
      ]
    }
  ],
  "customErrors": [
    {
      "name": "FailAmbiguousMergePerson",
      "label": "Ambiguous active person merge survivor",
      "locationX": 1180,
      "locationY": 420,
      "customErrorMessages": [
        {
          "errorMessage": "HubSpot contact merge resolved to multiple active NexusCRM people and cannot pick a survivor safely",
          "statusCode": "HUBSPOT_CONTACT_MERGE_AMBIGUOUS_PERSON"
        }
      ]
    }
  ]
}
