ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

[Extensibility Bug] codeunit 7307 "Whse.-Activity-Register" - Delete old Warehouse Activity Line extensibility

Open MicAlter31 opened this issue 3 years ago • 2 comments

Hi!

The recently published integration event #15513 to allow partners to add additional conditions for the warehouse activity line deletion. But the implementation doesn't really consider that the deletion logic is strongly depending to the "LineCount = 1" condition.

if GlobalWhseActivLine.Find('-') then
  repeat
      ShouldDeleteOldLine := (LineCount = 1) and
          ((OldWhseActivLine."Whse. Document Type" <> GlobalWhseActivLine."Whse. Document Type") or
           (OldWhseActivLine."Whse. Document No." <> GlobalWhseActivLine."Whse. Document No."));
      OnCodeOnAfterCalcShouldDeleteOldLine(OldWhseActivLine, GlobalWhseActivLine, ShouldDeleteOldLine);
      if ShouldDeleteOldLine then begin
          LineCount := 0;
          OldWhseActivLine.Delete();
      end;
      OldWhseActivLine := GlobalWhseActivLine;
      LineCount := LineCount + 1;
  until GlobalWhseActivLine.Next() = 0;

When using the new event it is impossible to determine if "LineCount = 1".

Also you can easily create an "Record not exist" error when setting the ShouldDeleteOldLine variable to true when running the first time through the code with LineCount = 0 and OldWhseActLine not initialized.

Just like:

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Whse.-Activity-Register", 'OnCodeOnAfterCalcShouldDeleteOldLine', '', true, true)]
    local procedure OnCodeOnAfterCalcShouldDeleteOldLine(OldWarehouseActivityLine: Record "Warehouse Activity Line"; WarehouseActivityLine: Record "Warehouse Activity Line"; var ShouldDeleteOldLine: Boolean)
    begin
        if ShouldDeleteOldLine then
            exit;

        ShouldDeleteOldLine := WarehouseActivityLine."Whse. Document Line No." <> OldWarehouseActivityLine."Whse. Document Line No.";
    end;

So it is very important for partners to know the content of the LineCount-variable.

Solution 1: New integration event with LineCount information:

if GlobalWhseActivLine.Find('-') then
  repeat
      ShouldDeleteOldLine := (LineCount = 1) and
          ((OldWhseActivLine."Whse. Document Type" <> GlobalWhseActivLine."Whse. Document Type") or
           (OldWhseActivLine."Whse. Document No." <> GlobalWhseActivLine."Whse. Document No."));
      OnCodeOnAfterCalcShouldDeleteOldLine(OldWhseActivLine, GlobalWhseActivLine, ShouldDeleteOldLine); //Obsolete=Pending
      OnCodeOnAfterCalcShouldDeleteOldLine2(OldWhseActivLine, GlobalWhseActivLine, LineCount, ShouldDeleteOldLine);
      if ShouldDeleteOldLine then begin
          LineCount := 0;
          OldWhseActivLine.Delete();
      end;
      OldWhseActivLine := GlobalWhseActivLine;
      LineCount := LineCount + 1;
  until GlobalWhseActivLine.Next() = 0;

with

[IntegrationEvent(false, false)]
local procedure OnCodeOnAfterCalcShouldDeleteOldLine2(OldWhseActivLine: Record "Warehouse Activity Line"; WhseActivLine: Record "Warehouse Activity Line"; LineCount: Integer; var ShouldDeleteOldLine: Boolean)
begin
end;

Solution 2: Exclude the "LineCount = 1" from the ShouldDeleteOldLine calculation and move it directly to the condition where the old warehouse activity line is deleted:

if GlobalWhseActivLine.Find('-') then
  repeat
      ShouldDeleteOldLine := (OldWhseActivLine."Whse. Document Type" <> GlobalWhseActivLine."Whse. Document Type") or
           (OldWhseActivLine."Whse. Document No." <> GlobalWhseActivLine."Whse. Document No.");
      OnCodeOnAfterCalcShouldDeleteOldLine(OldWhseActivLine, GlobalWhseActivLine, ShouldDeleteOldLine);
      if (LineCount = 1) and ShouldDeleteOldLine then begin
          LineCount := 0;
          OldWhseActivLine.Delete();
      end;
      OldWhseActivLine := GlobalWhseActivLine;
      LineCount := LineCount + 1;
  until GlobalWhseActivLine.Next() = 0;

MicAlter31 avatar Mar 20 '23 16:03 MicAlter31

Thanks for reporting this. We agree, and we’ll publish a fix asap, either in an update for the current version or in the next major release. Please do not reply to this, as we do not monitor closed issues. If you have follow-up questions or requests, please create a new issue where you reference this one.

Build ID: .

JesperSchulz avatar Nov 03 '23 13:11 JesperSchulz

Thanks for fixing this issue!

Only for information: It was fixed by adding the "LineCount" Variable to the existing Event Publisher. That's not something you notice so quickly ;)

image

MicAlter31 avatar Dec 12 '23 17:12 MicAlter31