Skip to content

[Event Request] codeunit 5817 "Undo Posting Management" - CollectItemLedgEntries procedure #30254

@salifmbaye28

Description

@salifmbaye28

Why do you need this change?

Dear support, in codeunit 5817 "Undo Posting Management" we need an event to handle the CollectItemLedgEntries function, since that function does not provide one; one of our clients had an implementation for this in NAV and we need to replicate it in BC.

Alternatives evaluated

The existing extensibility points are not sufficient because the customization must prevent the standard item ledger entry collection logic from running before CheckMissingItemLedgers is called.

The requirement is to skip the collection when the related item is marked as Without Inventory. Without a pre-event, the standard logic may attempt to collect item ledger entries that are not expected to exist and raise an error.

Performance / execution context for IsHandled

The event is raised once per execution of CollectItemLedgEntries. The subscriber only performs a small lookup on the source document line and related item to verify whether the item is marked as Without Inventory.

The expected performance impact is negligible.

Sensitive data assessment

The event does not expose any additional sensitive or private data. It only provides parameters that are already available within the procedure execution context.

Multi-extension interaction / conflict risk

As with any IsHandled event, conflicts are possible if multiple extensions attempt to override the same behavior.

In this scenario, the subscriber sets IsHandled := true only when the related item is marked as Without Inventory. This limits the risk of conflicts and ensures that the standard behavior remains unchanged for all other cases.

Describe the request

[IntegrationEvent(false, false)]
local procedure OnBeforeCollectItemLedgEntries(var TempItemLedgEntry: Record "Item Ledger Entry" temporary; SourceType: Integer; DocumentNo: Code[20]; LineNo: Integer; BaseQty: Decimal; EntryRef: Integer; var IsHandled: Boolean)
begin
end;

[Changes between **]

procedure CollectItemLedgEntries(var TempItemLedgEntry: Record "Item Ledger Entry" temporary; SourceType: Integer; DocumentNo: Code[20]; LineNo: Integer; BaseQty: Decimal; EntryRef: Integer)
var
    ItemLedgEntry: Record "Item Ledger Entry";
	** IsHandled: boolean; **
begin
	** 
	IsHandled := false;
	OnBeforeCollectItemLedgEntries(TempItemLedgEntry, SourceType, DocumentNo, LineNo, BaseQty, EntryRef, IsHandled);
	if IsHandled then
		exit;
	**
    TempItemLedgEntry.Reset();
    if not TempItemLedgEntry.IsEmpty() then
        TempItemLedgEntry.DeleteAll();
    if EntryRef <> 0 then begin
        ItemLedgEntry.Get(EntryRef); // Assertion: will fail if no entry exists.
        TempItemLedgEntry := ItemLedgEntry;
        TempItemLedgEntry.Insert();
    end else begin
        if ShouldRevertBaseQtySign(SourceType) then
            BaseQty := BaseQty * -1;
        CheckMissingItemLedgers(TempItemLedgEntry, SourceType, DocumentNo, LineNo, BaseQty);
    end;
end;

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions