[Extensibility Bug] codeunit 7307 "Whse.-Activity-Register" - Delete old Warehouse Activity Line extensibility
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;
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:
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 ;)