ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

[Event Request] table 36 "Sales Header".CreateDim

Open GMen66 opened this issue 3 years ago • 3 comments

Please move the event OnCreateDimOnBeforeUpdateLines before UpdateAllLineDim and add the new event OnCreateDimOnBeforeExistingDimensionsQst.

Actual Code:

procedure CreateDim(DefaultDimSource: List of [Dictionary of [Integer, Code[20]]])
var
    SourceCodeSetup: Record "Source Code Setup";
    OldDimSetID: Integer;
    IsHandled: Boolean;
begin
    IsHandled := false;
    OnBeforeCreateDim(Rec, IsHandled, DefaultDimSource);
    if IsHandled then
        exit;

    SourceCodeSetup.Get();
    #if not CLEAN20
    RunEventOnAfterCreateDimTableIDs(DefaultDimSource);
    #endif

    "Shortcut Dimension 1 Code" := '';
    "Shortcut Dimension 2 Code" := '';
    OldDimSetID := "Dimension Set ID";
    "Dimension Set ID" :=
      DimMgt.GetRecDefaultDimID(
        Rec, CurrFieldNo, DefaultDimSource, SourceCodeSetup.Sales, "Shortcut Dimension 1 Code", "Shortcut Dimension 2 Code", 0, 0);

    OnCreateDimOnBeforeUpdateLines(Rec, xRec, CurrFieldNo, OldDimSetID);

    if (OldDimSetID <> "Dimension Set ID") and (OldDimSetID <> 0) and guiallowed then
        if CouldDimensionsBeKept() then
            if Confirm(DoYouWantToKeepExistingDimensionsQst) then begin
                "Dimension Set ID" := OldDimSetID;
                DimMgt.UpdateGlobalDimFromDimSetID(Rec."Dimension Set ID", Rec."Shortcut Dimension 1 Code", Rec."Shortcut Dimension 2 Code");
            end;

    if (OldDimSetID <> "Dimension Set ID") and SalesLinesExist() then begin
        Modify();
        UpdateAllLineDim("Dimension Set ID", OldDimSetID);
    end;
end;

Suggestion:

procedure CreateDim(DefaultDimSource: List of [Dictionary of [Integer, Code[20]]])
var
    SourceCodeSetup: Record "Source Code Setup";
    OldDimSetID: Integer;
    IsHandled: Boolean;
begin
    IsHandled := false;
    OnBeforeCreateDim(Rec, IsHandled, DefaultDimSource);
    if IsHandled then
        exit;

    SourceCodeSetup.Get();
    #if not CLEAN20
    RunEventOnAfterCreateDimTableIDs(DefaultDimSource);
    #endif

    "Shortcut Dimension 1 Code" := '';
    "Shortcut Dimension 2 Code" := '';
    OldDimSetID := "Dimension Set ID";
    "Dimension Set ID" :=
      DimMgt.GetRecDefaultDimID(
        Rec, CurrFieldNo, DefaultDimSource, SourceCodeSetup.Sales, "Shortcut Dimension 1 Code", "Shortcut Dimension 2 Code", 0, 0);

    IsHandled := false;
    OnCreateDimOnBeforeExistingDimensionsQst(Rec, xRec, CurrFieldNo, OldDimSetID, IsHandled);
    if not IsHandled then
        if (OldDimSetID <> "Dimension Set ID") and (OldDimSetID <> 0) and guiallowed then
            if CouldDimensionsBeKept() then
                if Confirm(DoYouWantToKeepExistingDimensionsQst) then begin
                    "Dimension Set ID" := OldDimSetID;
                    DimMgt.UpdateGlobalDimFromDimSetID(Rec."Dimension Set ID", Rec."Shortcut Dimension 1 Code", Rec."Shortcut Dimension 2 Code");
                end;

    OnCreateDimOnBeforeUpdateLines(Rec, xRec, CurrFieldNo, OldDimSetID);

    if (OldDimSetID <> "Dimension Set ID") and SalesLinesExist() then begin
        Modify();
        UpdateAllLineDim("Dimension Set ID", OldDimSetID);
    end;
end;

[IntegrationEvent(true, false)]
local procedure OnCreateDimOnBeforeExistingDimensionsQst(var SalesHeader: Record "Sales Header"; xSalesHeader: Record "Sales Header"; CurrentFieldNo: Integer; OldDimSetID: Integer; var IsHandled: Boolean))
begin
end;

GMen66 avatar Mar 02 '23 12:03 GMen66

@GMen66 Does my requested event is enough for your purposes, too? https://github.com/microsoft/ALAppExtensions/issues/22113

pri-kise avatar Mar 02 '23 12:03 pri-kise

@pri-kise Yes, it's enough. It's better if the sale and purchase will have the same solution.

GMen66 avatar Mar 02 '23 14:03 GMen66

Please use existing publisher OnBeforeConfirmKeepExistingDimensions in procedure ConfirmKeepExistingDimensions for your scenario.

tomasevics avatar Jun 14 '23 09:06 tomasevics