Skip to content

[ExtensibilityRequest] CRM Integration Record - OnSetRecordSkipped #30407

Description

@BernhardKloibmueller

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    missing-infoThe issue misses information that prevents it from completion.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions