From 27eff206843ac0cb454e470e23a7ecd7250a1ab7 Mon Sep 17 00:00:00 2001 From: Onat Buyukakkus <55088871+onbuyuka@users.noreply.github.com> Date: Tue, 25 Aug 2026 00:42:21 +0200 Subject: [PATCH] [Extensibility Request] issue 30429: add events to disambiguate CRM integration table mappings Adds four integration events so extensions can select the correct "Integration Table Mapping" when multiple mappings share the same BC "Table ID" (for example, a Sales Header mapping that syncs quotes alongside the standard sales order mapping): - Codeunit "CRM Order Status Update Job" (UpdateSalesOrders): OnUpdateSalesOrdersOnBeforeFindIntegrationTableMapping - Table "Coupling Record Buffer" (Initialize): OnAfterInitialize - Codeunit "CRM Integration Management" (RemoveCoupling): OnRemoveCouplingOnBeforeGetIntegrationTableMappingForUncoupling - Codeunit "CRM Integration Management" (MatchBasedCoupling): OnMatchBasedCouplingOnBeforeGetIntegrationTableMappingForMatchBasedCoupling RecordRef context parameters are passed by value (read-only) so subscribers can inspect the source record without mutating caller state. Fixes AB#647520 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4f698109-800e-4840-b9b5-603e3e682257 --- .../D365Sales/CRMOrderStatusUpdateJob.Codeunit.al | 6 ++++++ .../Dataverse/CRMIntegrationManagement.Codeunit.al | 12 ++++++++++++ .../Dataverse/CouplingRecordBuffer.Table.al | 7 +++++++ 3 files changed, 25 insertions(+) diff --git a/src/Layers/W1/BaseApp/Integration/D365Sales/CRMOrderStatusUpdateJob.Codeunit.al b/src/Layers/W1/BaseApp/Integration/D365Sales/CRMOrderStatusUpdateJob.Codeunit.al index 861ca917f8a..dfa71c77f5f 100644 --- a/src/Layers/W1/BaseApp/Integration/D365Sales/CRMOrderStatusUpdateJob.Codeunit.al +++ b/src/Layers/W1/BaseApp/Integration/D365Sales/CRMOrderStatusUpdateJob.Codeunit.al @@ -58,6 +58,7 @@ codeunit 5352 "CRM Order Status Update Job" begin IntegrationTableMapping.SetRange(Type, IntegrationTableMapping.Type::Dataverse); IntegrationTableMapping.SetRange("Table ID", DATABASE::"Sales Header"); + OnUpdateSalesOrdersOnBeforeFindIntegrationTableMapping(IntegrationTableMapping); if IntegrationTableMapping.FindFirst() then IntegrationTableSynch.BeginIntegrationSynchJob(TABLECONNECTIONTYPE::CRM, IntegrationTableMapping, DATABASE::"Sales Header") else @@ -258,5 +259,10 @@ codeunit 5352 "CRM Order Status Update Job" if CRMPostBuffer.Get(TempCRMPostBuffer.ID) then CRMPostBuffer.Delete(); end; + + [IntegrationEvent(false, false)] + local procedure OnUpdateSalesOrdersOnBeforeFindIntegrationTableMapping(var IntegrationTableMapping: Record "Integration Table Mapping") + begin + end; } diff --git a/src/Layers/W1/BaseApp/Integration/Dataverse/CRMIntegrationManagement.Codeunit.al b/src/Layers/W1/BaseApp/Integration/Dataverse/CRMIntegrationManagement.Codeunit.al index 4c1e5ed2122..f0e3876d06c 100644 --- a/src/Layers/W1/BaseApp/Integration/Dataverse/CRMIntegrationManagement.Codeunit.al +++ b/src/Layers/W1/BaseApp/Integration/Dataverse/CRMIntegrationManagement.Codeunit.al @@ -1254,6 +1254,7 @@ codeunit 5330 "CRM Integration Management" exit; end; + OnRemoveCouplingOnBeforeGetIntegrationTableMappingForUncoupling(IntegrationTableMapping, LocalRecordRef); if GetIntegrationTableMappingForUncoupling(IntegrationTableMapping, LocalRecordRef.Number()) then if Schedule then ScheduleUncoupling(IntegrationTableMapping, IntegrationRecordSynch.GetTableViewForLocalRecords(LocalRecordRef), '') @@ -1340,6 +1341,7 @@ codeunit 5330 "CRM Integration Management" exit; end; + OnMatchBasedCouplingOnBeforeGetIntegrationTableMappingForMatchBasedCoupling(IntegrationTableMapping, LocalRecordRef); if GetIntegrationTableMappingForCoupling(IntegrationTableMapping, LocalRecordRef.Number()) then begin IntegrationFieldMapping.SetMatchBasedCouplingFilters(IntegrationTableMapping); if Page.RunModal(Page::"Match Based Coupling Criteria", IntegrationFieldMapping) = Action::LookupOK then @@ -4257,4 +4259,14 @@ codeunit 5330 "CRM Integration Management" local procedure OnBeforeRescheduleJobQueueEntries(TableNo: Integer; var RescheduleOffSetInMs: Integer) begin end; + + [IntegrationEvent(false, false)] + local procedure OnRemoveCouplingOnBeforeGetIntegrationTableMappingForUncoupling(var IntegrationTableMapping: Record "Integration Table Mapping"; LocalRecordRef: RecordRef) + begin + end; + + [IntegrationEvent(false, false)] + local procedure OnMatchBasedCouplingOnBeforeGetIntegrationTableMappingForMatchBasedCoupling(var IntegrationTableMapping: Record "Integration Table Mapping"; LocalRecordRef: RecordRef) + begin + end; } \ No newline at end of file diff --git a/src/Layers/W1/BaseApp/Integration/Dataverse/CouplingRecordBuffer.Table.al b/src/Layers/W1/BaseApp/Integration/Dataverse/CouplingRecordBuffer.Table.al index 51b28423b77..b539ff265a5 100644 --- a/src/Layers/W1/BaseApp/Integration/Dataverse/CouplingRecordBuffer.Table.al +++ b/src/Layers/W1/BaseApp/Integration/Dataverse/CouplingRecordBuffer.Table.al @@ -224,6 +224,8 @@ table 5332 "Coupling Record Buffer" "Saved CRM Option Id" := "CRM Option Id"; end; end; + + OnAfterInitialize(Rec); end; procedure Initialize(NAVRecordID: RecordID) @@ -426,5 +428,10 @@ table 5332 "Coupling Record Buffer" local procedure OnFindCRMOptionByName(CRMTableID: Integer; var EntityName: Text; var FieldName: Text; var Handled: Boolean) begin end; + + [IntegrationEvent(false, false)] + local procedure OnAfterInitialize(var CouplingRecordBuffer: Record "Coupling Record Buffer") + begin + end; }