Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Event Request] Codeunit 6501 - "Item Tracking Data Collection" - procedure TransferItemLedgToTempRec #27636

Open
IngoStender opened this issue Nov 15, 2024 · 0 comments

Comments

@IngoStender
Copy link

IngoStender commented Nov 15, 2024

Hello,

we need a new integration event OnTransferItemLedgToTempRecOnAfterSetLoadFieldsOnItemLedgerEntry() behind the ItemLedgEntry.SetLoadFields() in procedure TransferItemLedgToTempRec() in codeunit 6501 "Item Tracking Data Collection"

    procedure TransferItemLedgToTempRec(var ItemLedgEntry: Record "Item Ledger Entry"; var TrackingSpecification: Record "Tracking Specification" temporary)
    var
        IsHandled: Boolean;
    begin
        ItemLedgEntry.SetLoadFields(
          "Entry No.", "Item No.", "Variant Code", Positive, "Location Code", "Serial No.", "Lot No.", "Package No.",
          "Remaining Quantity", "Warranty Date", "Expiration Date");
        // >> New  
        OnTransferItemLedgToTempRecOnAfterSetLoadFieldsOnItemLedgerEntry(ItemLedgEntry);
        // << New
        if ItemLedgEntry.FindSet() then
            repeat
                if ItemLedgEntry.TrackingExists() and
                   not TempGlobalReservEntry.Get(-ItemLedgEntry."Entry No.", ItemLedgEntry.Positive)
                then begin
                    TempGlobalReservEntry.Init();
                    TempGlobalReservEntry."Entry No." := -ItemLedgEntry."Entry No.";
                    TempGlobalReservEntry."Reservation Status" := TempGlobalReservEntry."Reservation Status"::Surplus;
                    TempGlobalReservEntry.Positive := ItemLedgEntry.Positive;
                    TempGlobalReservEntry."Item No." := ItemLedgEntry."Item No.";
                    TempGlobalReservEntry."Variant Code" := ItemLedgEntry."Variant Code";
                    TempGlobalReservEntry."Location Code" := ItemLedgEntry."Location Code";
                    TempGlobalReservEntry."Quantity (Base)" := ItemLedgEntry."Remaining Quantity";
                    TempGlobalReservEntry."Source Type" := Database::"Item Ledger Entry";
                    TempGlobalReservEntry."Source Ref. No." := ItemLedgEntry."Entry No.";
                    TempGlobalReservEntry.CopyTrackingFromItemLedgEntry(ItemLedgEntry);
                    if TempGlobalReservEntry.Positive then begin

    // >> New
    [IntegrationEvent(false, false)]
    local procedure OnTransferItemLedgToTempRecOnAfterSetLoadFieldsOnItemLedgerEntry(var ItemLedgerEntry: Record "Item Ledger Entry")
    begin
    end;
    // << New

Additional context

Within the loop on item ledger entries, the procedure CopyTrackingFromItemLedgEntry() of table 337 "Reservation Entry" is called. This procedure transfers the Serial No. and Lot No. from the item ledger entry to the reservation entry and contains the integration event call OnAfterCopyTrackingFromItemLedgEntry() which provides the possibility for third party apps to transfer their additional item tracking fields. Because of the SetLoadFields on item ledger entries in procedure TransferItemLedgToTempRec(), additional item tracking fields are never loaded initially and needs to be retrieved by an additional database read.

In worst case, if an item ledger entry is changed (e.g. by a partial negative adjustment) between the ItemLedgEntry.FindSet() in procedure TransferItemLedgToTempRec() of codeunit "Item Tracking Data Collection" and the call of OnAfterCopyTrackingFromItemLedgEntry() in the reservation entry table, an error "The field 'Remaining Quantity' on table 'Item Ledger Entry' has changed in the database between initial and JIT load." occurs.

By providing the requested integration event it is possible to use the AddLoadFields() method to specifies additional fields to be initially loaded and to avoid unnecessary database reads.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant