[ExtensibilityRequest] CRM Integration Record - OnSetRecordSkipped
Why do you need this change?
We want to control which errors mark an integration record skipped. We have repeating errors which solve themselves from one run to the next and don't want to interfere with real errors in the integration where a user interaction indeed is needed. Sometimes the said error repeats and then the record gets marked as skipped. The current implementation of repeating the record is making it hard to filter on such errors and it is always a manual action which takes time.
We want to check the error messages and implement a change where we can control this better.
Describe the request
We would need multiple new events to control on which records we want to have new logic implemented as well to set the variables in a right manner.
table 5331 "CRM Integration Record"
Proposed changes in procedure IsSameFailureRepeatedTwice Before
[Scope('OnPrem')]
procedure IsSameFailureRepeatedTwice(RecRef: RecordRef; LastJobID: Guid; NewJobID: Guid): Boolean
var
IntegrationSynchJob: Record "Integration Synch. Job";
IntegrationSynchJobErrors: Record "Integration Synch. Job Errors";
LastError: Text;
NewError: Text;
begin
if IsNullGuid(LastJobID) or IsNullGuid(NewJobID) then
exit(false);
if IntegrationSynchJob.Get(LastJobID) then
if IntegrationSynchJob.GetErrorForRecordID(RecRef.RecordId, IntegrationSynchJobErrors) then
LastError := IntegrationSynchJobErrors.Message;
if IntegrationSynchJob.Get(NewJobID) then
if IntegrationSynchJob.GetErrorForRecordID(RecRef.RecordId, IntegrationSynchJobErrors) then
NewError := IntegrationSynchJobErrors.Message;
exit((LastError = NewError) and (NewError <> ''));
end;
After:
procedure IsSameFailureRepeatedTwice(RecRef: RecordRef; LastJobID: Guid; NewJobID: Guid) SameFailureRepeatedTwice: Boolean
var
IntegrationSynchJob: Record "Integration Synch. Job";
IntegrationSynchJobErrors: Record "Integration Synch. Job Errors";
LastError: Text;
NewError: Text;
begin
if IsNullGuid(LastJobID) or IsNullGuid(NewJobID) then
exit(false);
if IntegrationSynchJob.Get(LastJobID) then
if IntegrationSynchJob.GetErrorForRecordID(RecRef.RecordId, IntegrationSynchJobErrors) then
LastError := IntegrationSynchJobErrors.Message;
if IntegrationSynchJob.Get(NewJobID) then
if IntegrationSynchJob.GetErrorForRecordID(RecRef.RecordId, IntegrationSynchJobErrors) then
NewError := IntegrationSynchJobErrors.Message;
SameFailureRepeatedTwice := (LastError = NewError) and (NewError <> '');
OnAfterIsSameFailureRepeatedTwice(RecRef, LastJobID, NewJobID, LastError, NewError, SameFailureRepeatedTwice);
exit(SameFailureRepeatedTwice);
end;
[IntegrationEvent(false, false)]
local procedure OnAfterIsSameFailureRepeatedTwice(RecRef: RecordRef; LastJobID: Guid; NewJobID: Guid; LastError: Text; NewError: Text; var SameFailureRepeatedTwice: Boolean)
begin
end;
Proposed changes in procedure SetLastSynchResultFailed Before:
procedure SetLastSynchResultFailed(SourceRecRef: RecordRef; DirectionToIntTable: Boolean; JobId: Guid; var MarkedAsSkipped: Boolean)
var
Found: Boolean;
begin
if DirectionToIntTable then
Found := FindByRecordID(SourceRecRef.RecordId)
else
Found := FindByCRMID(GetCRMIdFromRecRef(SourceRecRef));
if Found then begin
if MarkedAsSkipped then
Skipped := true;
if DirectionToIntTable then begin
if (not Skipped) and ("Last Synch. CRM Result" = "Last Synch. CRM Result"::Failure) then
Skipped := IsSameFailureRepeatedTwice(SourceRecRef, "Last Synch. CRM Job ID", JobId);
"Last Synch. CRM Job ID" := JobId;
"Last Synch. CRM Result" := "Last Synch. CRM Result"::Failure
end else begin
if (not Skipped) and ("Last Synch. Result" = "Last Synch. Result"::Failure) then
Skipped := IsSameFailureRepeatedTwice(SourceRecRef, "Last Synch. Job ID", JobId);
"Last Synch. Job ID" := JobId;
"Last Synch. Result" := "Last Synch. Result"::Failure;
end;
if Skipped then
MarkedAsSkipped := true;
Modify(true);
end;
end;
After:
procedure SetLastSynchResultFailed(SourceRecRef: RecordRef; DirectionToIntTable: Boolean; JobId: Guid; var MarkedAsSkipped: Boolean)
var
Found: Boolean;
begin
if DirectionToIntTable then
Found := FindByRecordID(SourceRecRef.RecordId)
else
Found := FindByCRMID(GetCRMIdFromRecRef(SourceRecRef));
if Found then begin
if MarkedAsSkipped then
Skipped := true;
if DirectionToIntTable then begin
if (not Skipped) and ("Last Synch. CRM Result" = "Last Synch. CRM Result"::Failure) then begin
OnBeforeSetRecordSkippedCRM(Rec, SourceRecRef);
Skipped := IsSameFailureRepeatedTwice(SourceRecRef, "Last Synch. CRM Job ID", JobId);
OnAfterSetRecordSkippedCRM(Rec, SourceRecRef);
end;
"Last Synch. CRM Job ID" := JobId;
"Last Synch. CRM Result" := "Last Synch. CRM Result"::Failure
end else begin
if (not Skipped) and ("Last Synch. Result" = "Last Synch. Result"::Failure) then begin
OnBeforeSetRecordSkipped(Rec, SourceRecRef);
Skipped := IsSameFailureRepeatedTwice(SourceRecRef, "Last Synch. Job ID", JobId);
OnAfterSetRecordSkipped(Rec, SourceRecRef);
end;
"Last Synch. Job ID" := JobId;
"Last Synch. Result" := "Last Synch. Result"::Failure;
end;
if Skipped then
MarkedAsSkipped := true;
Modify(true);
end;
end;
[IntegrationEvent(false, false)]
local procedure OnBeforeSetRecordSkipped(var CRMIntegrationRecord: Record "CRM Integration Record"; SourceRecRef: RecordRef)
begin
end;
[IntegrationEvent(false, false)]
local procedure OnAfterSetRecordSkipped(var CRMIntegrationRecord: Record "CRM Integration Record"; SourceRecRef: RecordRef)
begin
end;
[IntegrationEvent(false, false)]
local procedure OnBeforeSetRecordSkippedCRM(var CRMIntegrationRecord: Record "CRM Integration Record"; SourceRecRef: RecordRef)
begin
end;
[IntegrationEvent(false, false)]
local procedure OnAfterSetRecordSkippedCRM(var CRMIntegrationRecord: Record "CRM Integration Record"; SourceRecRef: RecordRef)
begin
end;
EDIT regarding missing information I would suggest the SourceRecRef as parameter because no additional database transaction is needed to retrieve data regarding the source of the integration record. If you use a RecordId parameter then you have to read again the record and possibly trigger more database transactions. This is a performance point of view. Internal work item: AB#646539
Hi @BernhardKloibmueller,
Thank you for your extensibility request. To help us process it efficiently, please update the issue to include the required information.
Missing Information:
- Justification for
RecordRefevent parameters: Please clarify whyRecordRefis necessary for subscribers in the requested events and why a safer alternative such asRecordIdor typed record parameters would not be sufficient.
Please update the issue with the missing details. We'll automatically re-analyze once updated.
[!NOTE] Automatically generated by the Triage Agent — advisory only. An engineer will review before any action is taken.
[!TIP] Not accurate? Reply with
/not-accurate(optional: add a short explanation). Your feedback improves future responses.
✅ Analysis complete - ready for further processing
Implementation:
Add integration events in SetLastSynchResultFailed() around the repeated-failure skip logic for both directions, and add an OnAfterIsSameFailureRepeatedTwice event in IsSameFailureRepeatedTwice() so subscribers can override the repeated-failure decision based on the compared error messages.
Location in SetLastSynchResultFailed() and IsSameFailureRepeatedTwice() procedures:
procedure SetLastSynchResultFailed(SourceRecRef: RecordRef; DirectionToIntTable: Boolean; JobId: Guid; var MarkedAsSkipped: Boolean)
var
Found: Boolean;
begin
if DirectionToIntTable then
Found := FindByRecordID(SourceRecRef.RecordId)
else
Found := FindByCRMID(GetCRMIdFromRecRef(SourceRecRef));
if Found then begin
if MarkedAsSkipped then
Skipped := true;
if DirectionToIntTable then begin
if (not Skipped) and ("Last Synch. CRM Result" = "Last Synch. CRM Result"::Failure) then begin
OnSetLastSynchResultFailedOnBeforeSetCRMRecordSkipped(SourceRecRef, "Last Synch. CRM Job ID", JobId, Skipped);
Skipped := IsSameFailureRepeatedTwice(SourceRecRef, "Last Synch. CRM Job ID", JobId);
OnSetLastSynchResultFailedOnAfterSetCRMRecordSkipped(SourceRecRef, "Last Synch. CRM Job ID", JobId, Skipped);
end;
"Last Synch. CRM Job ID" := JobId;
"Last Synch. CRM Result" := "Last Synch. CRM Result"::Failure
end else begin
if (not Skipped) and ("Last Synch. Result" = "Last Synch. Result"::Failure) then begin
OnSetLastSynchResultFailedOnBeforeSetRecordSkipped(SourceRecRef, "Last Synch. Job ID", JobId, Skipped);
Skipped := IsSameFailureRepeatedTwice(SourceRecRef, "Last Synch. Job ID", JobId);
OnSetLastSynchResultFailedOnAfterSetRecordSkipped(SourceRecRef, "Last Synch. Job ID", JobId, Skipped);
end;
"Last Synch. Job ID" := JobId;
"Last Synch. Result" := "Last Synch. Result"::Failure;
end;
if Skipped then
MarkedAsSkipped := true;
Modify(true);
end;
end;
[Scope('OnPrem')]
procedure IsSameFailureRepeatedTwice(RecRef: RecordRef; LastJobID: Guid; NewJobID: Guid): Boolean
var
IntegrationSynchJob: Record "Integration Synch. Job";
IntegrationSynchJobErrors: Record "Integration Synch. Job Errors";
LastError: Text;
NewError: Text;
IsRepeatedFailure: Boolean;
begin
if IsNullGuid(LastJobID) or IsNullGuid(NewJobID) then
exit(false);
if IntegrationSynchJob.Get(LastJobID) then
if IntegrationSynchJob.GetErrorForRecordID(RecRef.RecordId, IntegrationSynchJobErrors) then
LastError := IntegrationSynchJobErrors.Message;
if IntegrationSynchJob.Get(NewJobID) then
if IntegrationSynchJob.GetErrorForRecordID(RecRef.RecordId, IntegrationSynchJobErrors) then
NewError := IntegrationSynchJobErrors.Message;
IsRepeatedFailure := (LastError = NewError) and (NewError <> '');
OnAfterIsSameFailureRepeatedTwice(RecRef, LastJobID, NewJobID, LastError, NewError, IsRepeatedFailure);
exit(IsRepeatedFailure);
end;
Event Publisher (add at the end of the codeunit with other events):
[IntegrationEvent(false, false)]
local procedure OnAfterIsSameFailureRepeatedTwice(var SourceRecRef: RecordRef; LastJobId: Guid; NewJobId: Guid; LastError: Text; NewError: Text; var IsRepeatedFailure: Boolean)
begin
end;
[IntegrationEvent(false, false)]
local procedure OnSetLastSynchResultFailedOnBeforeSetRecordSkipped(var SourceRecRef: RecordRef; LastJobId: Guid; NewJobId: Guid; var Skipped: Boolean)
begin
end;
[IntegrationEvent(false, false)]
local procedure OnSetLastSynchResultFailedOnAfterSetRecordSkipped(var SourceRecRef: RecordRef; LastJobId: Guid; NewJobId: Guid; var Skipped: Boolean)
begin
end;
[IntegrationEvent(false, false)]
local procedure OnSetLastSynchResultFailedOnBeforeSetCRMRecordSkipped(var SourceRecRef: RecordRef; LastJobId: Guid; NewJobId: Guid; var Skipped: Boolean)
begin
end;
[IntegrationEvent(false, false)]
local procedure OnSetLastSynchResultFailedOnAfterSetCRMRecordSkipped(var SourceRecRef: RecordRef; LastJobId: Guid; NewJobId: Guid; var Skipped: Boolean)
begin
end;
File: CRMIntegrationRecord.Table.al
[!NOTE] Automatically generated by the Triage Agent — advisory only. An engineer will review before any action is taken.
[!TIP] Not accurate? Reply with
/not-accurate(optional: add a short explanation). Your feedback improves future responses.
please do not forget to look into removing [Scope('OnPrem')] from procedure IsSameFailureRepeatedTwice. Thank you
Thanks @BernhardKloibmueller — the underlying need (transient, self-healing errors shouldn't permanently mark a record Skipped) is legitimate. But I don't think we can take the change in the shape proposed, and I want to explain why and point you at the right place to drive it.
Why not a var override. IsSameFailureRepeatedTwice → Skipped := true is a deliberate circuit breaker: once the same error repeats, the engine stops auto-retrying that record until someone intervenes. An event that lets a subscriber force the result back to "not a repeat" / "don't skip" removes that breaker — and because the code can't tell a genuinely transient error from a persistent one, a record whose error doesn't self-heal would then be re-synced and fail every cycle, indefinitely (job-queue churn, telemetry noise, Dataverse API throttling). Shipping a base-product hook that can disable the safety net isn't something we want to do.
What would be supportable instead — an observational event. A by-value OnAfter (no var, so it can't change the outcome) gives you exactly the visibility you're after — to filter/telemetry these errors and, if you want, trigger your own automated restore via the existing un-skip path — while leaving the breaker intact:
[IntegrationEvent(false, false)]
local procedure OnAfterIsSameFailureRepeatedTwice(SourceRecordId: RecordId; LastJobID: Guid; NewJobID: Guid; LastError: Text; NewError: Text; SameFailureRepeatedTwice: Boolean)
begin
end;
Note RecordId rather than RecordRef (matches this table's existing events, e.g. OnBeforeIsModifiedAfterLastSynchronizedRecord), and the result passed by value.
Where to take it. Table 5331 "CRM Integration Record" is Base Application code, which is now open source in microsoft/BCApps — it isn't in this repo. That's also where you can contribute the event yourself. The process (CONTRIBUTING.md has the details):
- Open an issue in microsoft/BCApps describing the observational event (you can reuse the rationale here). Note that blank issues are disabled — pick the appropriate template.
- Wait for it to be approved (it gets an
approvedlabel). An approved issue is required before a PR — this makes sure your time isn't wasted on something that can't be accepted. - Submit the PR linked with
Fixes #<id>and sign the CLA. BCApps is a contribution model, so the PR would be yours to author. - The PR is built and auto-reviewed against BCQuality best practices by the Copilot review agent — a strongly-typed, by-value event like the above is exactly what those checks expect, so it should sail through, whereas a
RecordRef/var-bypass shape would get flagged.
I'll close this request here in favor of that path, since the code lives in BCApps. If you open the BCApps issue, feel free to link it back here for continuity. Thanks again for the well-documented request!