ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

[Event Request] codeunit 99000831 "Reservation Engine Mgt." - New event OnCloseReservEntryOnAfterGetItem

Open petmoe opened this issue 1 year ago • 1 comments

Why do you need this change?

We would like to be able to utilize the AutoTrack functionality dynamically when certain conditions are fulfilled without having to set up the item to run AutoTrack all the time. We have requested an event in "Reservation Management" codeunit (#29421), to allow us to access the global Item variable, but we have a similar challenge in "Reservation Engine Mgt." which is called as part of the AutoTrack processing. Getting access to the global Item parameter through the new event, will allow us to set the Item."Order Tracking Policy" temporarily and thus ensure that the procedure CloseReservEntry will leave non-tracked entries as surplus records, as it is supposed to happen when running Order Tracking.

Describe the request

In codeunit 99000831 "Reservation Engine Mgt." - procedure CloseReservEntry(ReservEntry: Record "Reservation Entry"; ReTrack: Boolean; DeleteAll: Boolean) we would like a new integration event OnCloseReservEntryOnAfterGetItem placed just after the call of GetItem(ReservEntry."Item No."). The event should expose the variables ReservEntry and Item as shown below.

procedure CloseReservEntry(ReservEntry: Record "Reservation Entry"; ReTrack: Boolean; DeleteAll: Boolean)
var
    ReservEntry2: Record "Reservation Entry";
    SurplusReservEntry: Record "Reservation Entry";
    DummyReservEntry: Record "Reservation Entry";
    OriginalReservEntry2: Record "Reservation Entry";
    TotalQty: Decimal;
    AvailabilityDate: Date;
    SkipDeleteReservEntry: Boolean;
begin
    OnBeforeCloseReservEntry(ReservEntry, ReTrack, DeleteAll, SkipDeleteReservEntry);
    if not SkipDeleteReservEntry then
        ReservEntry.Delete();
    if ReservEntry."Reservation Status" = ReservEntry."Reservation Status"::Prospect then
        exit;

    ModifyActionMessage(ReservEntry);

    if ReservEntry."Reservation Status" <> ReservEntry."Reservation Status"::Surplus then begin
        GetItem(ReservEntry."Item No.");
        //>> New Code Begin
        OnCloseReservEntryOnAfterGetItem(ReservEntry, Item);
        //<< New Code End
        ReservEntry2.Get(ReservEntry."Entry No.", not ReservEntry.Positive);
        OnCloseReservEntryOnAfterReservEntry2Get(ReservEntry2, ReservEntry);
        OriginalReservEntry2 := ReservEntry2;
        if (Item."Order Tracking Policy" = Item."Order Tracking Policy"::None) and
           (not TransferLineWithItemTracking(ReservEntry2)) and
           (((ReservEntry.Binding = ReservEntry.Binding::"Order-to-Order") and ReservEntry2.Positive) or
            (ReservEntry2."Source Type" = Database::"Item Ledger Entry") or not ReservEntry2.TrackingExists())
        then
            ReservEntry2.Delete()
        else begin
            ReservEntry2."Reservation Status" := ReservEntry2."Reservation Status"::Surplus;

            if ReservEntry2.Positive then begin
                AvailabilityDate := ReservEntry2."Expected Receipt Date";
                ReservEntry2."Shipment Date" := 0D
            end else begin
                AvailabilityDate := ReservEntry2."Shipment Date";
                ReservEntry2."Expected Receipt Date" := 0D;
            end;
            ReservEntry2.Modify();
            ReservMgt.SetSkipUntrackedSurplus(true);
            ReservEntry2."Quantity (Base)" :=
              ReservMgt.MatchSurplus(ReservEntry2, SurplusReservEntry, ReservEntry2."Quantity (Base)", not ReservEntry2.Positive,
                AvailabilityDate, Item."Order Tracking Policy");
            if ReservEntry2."Quantity (Base)" = 0 then begin
                OnCloseReservEntryOnBeforeDeleteReservEntry2(ReservEntry2, OriginalReservEntry2);
                ReservEntry2.Delete(true);
            end else begin
                ReservEntry2.Validate("Quantity (Base)");
                ReservEntry2.Validate(Binding, ReservEntry2.Binding::" ");
                if Item."Order Tracking Policy" <> Item."Order Tracking Policy"::None then
                    ReservEntry2."Untracked Surplus" := ReservEntry2.IsResidualSurplus();
                OnCloseReservEntryOnBeforeModifyReservEntry2(ReservEntry2, OriginalReservEntry2);
                ReservEntry2.Modify();

                if Item."Order Tracking Policy" = Item."Order Tracking Policy"::"Tracking & Action Msg." then begin
                    ModifyActionMessageDating(ReservEntry2);
                    if DeleteAll then
                        ReservMgt.IssueActionMessage(ReservEntry2, false, ReservEntry)
                    else
                        ReservMgt.IssueActionMessage(ReservEntry2, false, DummyReservEntry);
                end;
            end;
        end;
    end;

    if ReTrack then begin
        TotalQty := ReservMgt.SourceQuantity(ReservEntry, true);
        ReservMgt.AutoTrack(TotalQty);
    end;

    OnAfterCloseReservEntry(ReservEntry);
end;

//>>New Code Begin
[IntegrationEvent(false, false)]
local procedure OnCloseReservEntryOnAfterGetItem(var ReservationEntry: Record "Reservation Entry"; var Item: Record Item)
begin
end;
//>>New Code End

Internal work item: AB#613336

petmoe avatar Nov 16 '25 16:11 petmoe

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: 43395.

JesperSchulz avatar Dec 11 '25 20:12 JesperSchulz