Skip to content

[W1][Codeunit][22][Item Jnl.-Post Line] Add integration event OnReApplyOnBeforeCreateItemJnlLineFromEntryApplyWithZero in ReApply before CreateItemJnlLineFromEntry when ApplyWith is 0 #30041

@mavohra

Description

@mavohra

Why do you need this change?

We need to intercept the CreateItemJnlLineFromEntry call inside the ApplyWith = 0 branch of ReApply to supply additional quantity data when populating the item journal line from the entry.

The standard CreateItemJnlLineFromEntry receives only ItemLedgEntry and ItemLedgEntry."Remaining Quantity", with no mechanism to pass additional quantity fields. Items with alternate units of measure carry a "Remaining Quantity (Alt.)" field that must also be transferred to the item journal line for the downstream ApplyItemLedgEntry call to process correctly.

No event exists between the ItemLedgEntry."Applies-to Entry" := ApplyWith assignment and the CreateItemJnlLineFromEntry call in this branch. OnBeforeReApply fires at procedure entry before item tracking setup, entry switching, and the ApplyWith branch decision are resolved. OnReApplyOnBeforeStartApply is only reached inside the ApplyWith <> 0 branch and is never fired when ApplyWith = 0. OnReApplyOnBeforeUpdateLinkedValuationDate fires after EnsureValueEntryLoaded later in the same branch, after CreateItemJnlLineFromEntry and ApplyItemLedgEntry have already run, making it too late to affect the journal line creation.

Describe the request

Add an integration event OnReApplyOnBeforeCreateItemJnlLineFromEntryApplyWithZero in ReApply in Codeunit 22 "Item Jnl.-Post Line" after ItemLedgEntry."Applies-to Entry" := ApplyWith and before CreateItemJnlLineFromEntry in the ApplyWith = 0 branch.

        end else begin  // ApplyWith is 0
            ItemLedgEntry."Applies-to Entry" := ApplyWith;
            IsHandled := false;
            OnReApplyOnBeforeCreateItemJnlLineFromEntryApplyWithZero(ItemLedgEntry, ItemJnlLine, IsHandled); // <---- New Event
            if not IsHandled then
                CreateItemJnlLineFromEntry(ItemLedgEntry, ItemLedgEntry."Remaining Quantity", ItemJnlLine);
            ItemJnlLine."Applies-to Entry" := ItemLedgEntry."Applies-to Entry";
            GlobalItemLedgEntry := ItemLedgEntry;
            ApplyItemLedgEntry(ItemLedgEntry, OldItemLedgEntry, ValueEntry, false);
            TouchItemEntryCost(ItemLedgEntry, false);
            ItemLedgEntry.Modify();

Event Signature:

[IntegrationEvent(false, false)]
local procedure OnReApplyOnBeforeCreateItemJnlLineFromEntryApplyWithZero(var ItemLedgEntry: Record "Item Ledger Entry"; var ItemJnlLine: Record "Item Journal Line"; var IsHandled: Boolean)
begin
end;

Alternatives evaluated: OnBeforeReApply fires at procedure entry before item tracking setup and the ApplyWith branch decision, so no entry or journal line data is yet resolved at that point. OnReApplyOnBeforeStartApply is raised only inside the ApplyWith <> 0 branch and is never reached when ApplyWith = 0. OnReApplyOnBeforeUpdateLinkedValuationDate fires after EnsureValueEntryLoaded later in the ApplyWith = 0 branch, by which point CreateItemJnlLineFromEntry and ApplyItemLedgEntry have already completed, making it too late to modify the journal line creation. No event currently exists before CreateItemJnlLineFromEntry in the ApplyWith = 0 branch of ReApply.
Internal work item: AB#638499

Metadata

Metadata

Assignees

No one assigned

    Labels

    SCMGitHub request for SCM areaevent-requestRequest for adding an event

    Type

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions