microsoft / microsoft/ALAppExtensions

[W1][Codeunit][22][Item Jnl.-Post Line] Add integration event OnCostApplyOnBeforeSetGlobalItemLedgEntry in CostApply before inbound and apply-with entry assignment

Open
#30,042 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

missing-info
Dominant language
AL
Stars
988
Forks
692
Avg merge
49m
Merged PRs (30d)
1

Description

Why do you need this change?

We need to override the condition that determines which of the two item ledger entries is treated as the inbound (cost-providing) entry inside CostApply. The standard code evaluates ItemLedgEntry.Quantity > 0 to assign GlobalItemLedgEntry and ApplyWithItemLedgEntry, but items with alternate units of measure may carry a non-zero alternate quantity when the base Quantity is zero, requiring a different condition to correctly identify the inbound entry.

The standard condition assigns GlobalItemLedgEntry and ApplyWithItemLedgEntry unconditionally based solely on Quantity. All subsequent logic in CostApply, including CheckIsCyclicalLoop, CreateItemJnlLineFromEntry, InsertApplEntry, and valuation date updates, depends on those two assignments being correct. There is no way to correct the assignment after the fact without re-entering the procedure.

OnCostApplyOnBeforeInsertApplEntry fires inside the CheckIsCyclicalLoop block after both GlobalItemLedgEntry and ApplyWithItemLedgEntry have already been set, making it too late to change which entry is the cost provider. No event exists before the if ItemLedgEntry.Quantity > 0 block that exposes both entries and the two assignment targets.

Describe the request

Add an integration event OnCostApplyOnBeforeSetGlobalItemLedgEntry in CostApply in Codeunit 22 "Item Jnl.-Post Line" at the start of the procedure before the block that assigns GlobalItemLedgEntry and ApplyWithItemLedgEntry.

    local procedure CostApply(var ItemLedgEntry: Record "Item Ledger Entry"; ItemLedgEntry2: Record "Item Ledger Entry")
    var
        ApplyWithItemLedgEntry: Record "Item Ledger Entry";
        ValueEntry: Record "Value Entry";
        IsHandled: Boolean;
    begin
        IsHandled := false;
        OnCostApplyOnBeforeSetGlobalItemLedgEntry(ItemLedgEntry, ItemLedgEntry2, GlobalItemLedgEntry, ApplyWithItemLedgEntry, IsHandled); // <---- New Event
        if not IsHandled then
            if ItemLedgEntry.Quantity > 0 then begin
                GlobalItemLedgEntry := ItemLedgEntry;
                ApplyWithItemLedgEntry := ItemLedgEntry2;
            end
            else begin
                GlobalItemLedgEntry := ItemLedgEntry2;
                ApplyWithItemLedgEntry := ItemLedgEntry;
            end;
        if not ItemApplnEntry.CheckIsCyclicalLoop(ApplyWithItemLedgEntry, GlobalItemLedgEntry) then begin
            CreateItemJnlLineFromEntry(GlobalItemLedgEntry, GlobalItemLedgEntry.Quantity, ItemJnlLine);

Event Signature:

[IntegrationEvent(false, false)]
local procedure OnCostApplyOnBeforeSetGlobalItemLedgEntry(var ItemLedgEntry: Record "Item Ledger Entry"; var ItemLedgEntry2: Record "Item Ledger Entry"; var GlobalItemLedgEntry: Record "Item Ledger Entry"; var ApplyWithItemLedgEntry: Record "Item Ledger Entry"; var IsHandled: Boolean)
begin
end;

Alternatives evaluated: OnCostApplyOnBeforeInsertApplEntry fires inside the if not ItemApplnEntry.CheckIsCyclicalLoop(...) block after both GlobalItemLedgEntry and ApplyWithItemLedgEntry have already been assigned, so a subscriber there cannot change which entry is treated as the cost provider. No event currently exists before the if ItemLedgEntry.Quantity > 0 assignment block in CostApply.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read Codeunit 22 "Item Jnl.-Post Line", focusing on the CostApply procedure and the existing OnCostApplyOnBeforeInsertApplEntry event. Confirm the requested event can expose both ledger entries and assignment targets before the Quantity condition; done means subscribers can override the selection while the existing path remains unchanged when IsHandled is false.

Written by the indexing model from the issue text.

Assessment

Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.