[W1][Table][5330][CRM Connection Setup] Add Event to Skip ResetSalesOrderMappingConfiguration
Why do you need this change?
When enabling CRM Connection Setup, all table mappings, field mappings, and job queue entries are reset to their default values.
With every major Business Central update, we are required to redeploy the CRM solution to upgrade it to the latest version. This process forces us to:
- Disable the CRM Connection
- Redeploy the solution
- Enable the CRM Connection again
Re-enabling the connection always resets all customer-specific mappings and job queue settings. This frequently causes sync issues such as duplicate records and overwritten data.
To mitigate this risk, we need a way to skip the automatic reset of the CRM configuration during re-enablement.
The main ResetConfiguration function in the CRM Setup Defaults codeunit already contains an event
However, the Sales Order mapping is reset in a separate location, directly in the OnValidate trigger of the "Is Enabled" field. This reset cannot be bypassed, which makes it impossible to fully prevent the configuration reset even when handling the main reset through an event.
Describe the request
We need to be able to skip the line CRMSetupDefaults.ResetSalesOrderMappingConfiguration(Rec)
A new event with an IsHandled above this line would be enough. Alternatively, an event could be added inside the ResetSalesOrderMappingConfiguration function in the Codeunit "CRM Setup Defaults":
Hi @az-ha,
Thanks for submitting this extensibility request. To help us process it efficiently, please update the issue to include the required information.
Missing Information:
-
Performance Considerations: Expected execution frequency and potential impact assessment.
-
Data Sensitivity Review: Confirmation that no sensitive data is exposed through this event, or rationale if sensitive data access is necessary. Please confirm whether the
CRM Connection Setuprecord passed to the event contains any sensitive configuration data. -
Multi-Extension Interaction: Please describe potential risks if multiple extensions subscribe to this event and how conflicts would be mitigated. For example, what happens if multiple extensions each want to handle the reset differently?
Please update the issue with the missing details. We'll automatically re-analyze once updated.
Hi @AleksandricMarko
Thanks for the quick reply.
- Performance considerations: The event would only execute when the CRM Connection Setup is enabled or re-enabled. The performance impact should be exactly the same as in the ResetConfiguration function in the CRM Setup Defaults codeunit, which already contains an event with the same behaviour. Performance impact is negligable.
- Data Sensitivity Review: The same as in the ResetConfiguration Event. No sensitive data is exposed.
- Multi-Extension Interaction: It would have the same behaviour as the ResetConfiguration Event, as we only need the parameters CRM Connection Setup and IsHandled. Other extensions should be aware of the IsHandled design pattern.
Hi @AleksandricMarko,
is the request accepted or do you need more information?
Best regards René
✅ Analysis complete - approved for implementation
Implementation:
Add a new integration event at the beginning of the ResetSalesOrderMappingConfiguration() procedure in Codeunit 5334 "CRM Setup Defaults" to allow extensions to skip the entire procedure execution.
Location in ResetSalesOrderMappingConfiguration() procedure (around line 1869):
[Scope('OnPrem')]
procedure ResetSalesOrderMappingConfiguration(CRMConnectionSetup: Record "CRM Connection Setup")
var
JobQueueEntry: Record "Job Queue Entry";
IntegrationTableMapping: Record "Integration Table Mapping";
EnqueueJobQueueEntries: Boolean;
IsTeamOwnershipModel: Boolean;
IsHandled: Boolean;
begin
IsHandled := false;
OnBeforeResetSalesOrderMappingConfiguration(CRMConnectionSetup, IsHandled);
if IsHandled then
exit;
EnqueueJobQueueEntries := CRMConnectionSetup.DoReadCRMData();
IsTeamOwnershipModel := CDSIntegrationMgt.IsTeamOwnershipModelSelected();
// ... rest of existing code ...
end;
Event Publisher (add at the end of the codeunit with other events):
[IntegrationEvent(false, false)]
local procedure OnBeforeResetSalesOrderMappingConfiguration(CRMConnectionSetup: Record "CRM Connection Setup"; var IsHandled: Boolean)
begin
end;
File: CRMSetupDefaults.Codeunit.al
I don't think this event is necessary. If you look at ResetSalesOrderMappingConfiguration procedure, you'll notice the calls to ResetBidirectionalSalesOrderMapping and ResetBidirectionalSalesOrderLineMapping or ResetSalesOrderMapping based on the sales order integration setting (bidirectional or legacy).
procedure ResetSalesOrderMappingConfiguration(CRMConnectionSetup: Record "CRM Connection Setup")
var
JobQueueEntry: Record "Job Queue Entry";
IntegrationTableMapping: Record "Integration Table Mapping";
EnqueueJobQueueEntries: Boolean;
IsTeamOwnershipModel: Boolean;
begin
EnqueueJobQueueEntries := CRMConnectionSetup.DoReadCRMData();
IsTeamOwnershipModel := CDSIntegrationMgt.IsTeamOwnershipModelSelected();
if CRMConnectionSetup."Bidirectional Sales Order Int." then begin
**ResetBidirectionalSalesOrderMapping('SALESORDER-ORDER', IsTeamOwnershipModel, EnqueueJobQueueEntries);
ResetBidirectionalSalesOrderLineMapping('SOLINE-ORDERDETAIL');**
JobQueueEntry.SetRange("Object Type to Run", JobQueueEntry."Object Type to Run"::Codeunit);
JobQueueEntry.SetFilter("Object ID to Run", '%1|%2|%3', Codeunit::"Auto Create Sales Orders", Codeunit::"CRM Order Status Update Job", Codeunit::"CRM Notes Synch Job");
JobQueueEntry.DeleteAll();
RecreateSalesOrderNotesJobQueueEntry(EnqueueJobQueueEntries);
RecreateArchivedSalesOrdersJobQueueEntry(EnqueueJobQueueEntries);
end;
if CRMConnectionSetup."Is S.Order Integration Enabled" then begin
**ResetSalesOrderMapping('SALESORDER-ORDER', IsTeamOwnershipModel, EnqueueJobQueueEntries);**
if IntegrationTableMapping.Get('SOLINE-ORDERDETAIL') then begin
JobQueueEntry.SetRange("Object Type to Run", JobQueueEntry."Object Type to Run"::Codeunit);
JobQueueEntry.SetRange("Object ID to Run", Codeunit::"Integration Synch. Job Runner");
JobQueueEntry.SetRange("Record ID to Process", IntegrationTableMapping.RecordId);
JobQueueEntry.DeleteAll();
IntegrationTableMapping.Delete()
end;
RecreateSalesOrderStatusJobQueueEntry(EnqueueJobQueueEntries);
RecreateSalesOrderNotesJobQueueEntry(EnqueueJobQueueEntries);
CODEUNIT.Run(CODEUNIT::"CRM Enable Posts");
end;
end;
And all these three procedures have already IsHandled events defined:
- ResetBidirectionalSalesOrderMapping
procedure ResetBidirectionalSalesOrderMapping(IntegrationTableMappingName: Code[20]; IsTeamOwnershipModel: Boolean; EnqueueJobQueEntry: Boolean)
var
IntegrationTableMapping: Record "Integration Table Mapping";
IntegrationFieldMapping: Record "Integration Field Mapping";
SalesHeader: Record "Sales Header";
CRMSalesorder: Record "CRM Salesorder";
CDSCompany: Record "CDS Company";
EmptyGuid: Guid;
IsHandled: Boolean;
begin
OnBeforeResetBidirectionalSalesOrderMapping(IntegrationTableMappingName, EnqueueJobQueEntry, IsHandled);
if IsHandled then
exit;
- ResetBidirectionalSalesOrderLineMapping
var
IntegrationTableMapping: Record "Integration Table Mapping";
IntegrationFieldMapping: Record "Integration Field Mapping";
SalesLine: Record "Sales Line";
CRMSalesorderdetail: Record "CRM Salesorderdetail";
IsHandled: Boolean;
begin
OnBeforeResetBidirectionalSalesOrderLineMapping(IntegrationTableMappingName, IsHandled);
if IsHandled then
exit;
- ResetSalesOrderMapping
procedure ResetSalesOrderMapping(IntegrationTableMappingName: Code[20]; IsTeamOwnershipModel: Boolean; EnqueueJobQueEntry: Boolean)
var
IntegrationTableMapping: Record "Integration Table Mapping";
IntegrationFieldMapping: Record "Integration Field Mapping";
SalesHeader: Record "Sales Header";
CRMSalesorder: Record "CRM Salesorder";
CDSCompany: Record "CDS Company";
EmptyGuid: Guid;
IsHandled: Boolean;
begin
OnBeforeResetSalesOrderMapping(IntegrationTableMappingName, EnqueueJobQueEntry, IsHandled);
if IsHandled then
exit;
Hi @onbuyuka
Thanks a lot for pointing this out. I hadn’t noticed that there were already events in the functions being called inside the one where we wanted to add the IsHandled event. This solves our problem, appreciate your help!