ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

Codeunit 1032 - "Job Planning Line-Reserve".UpdateReservationsWhenPostingJobPlaningLineNegativeAdjFromPO

Open JellebBE opened this issue 1 year ago • 6 comments

Why do you need this change?

We want to create extra functionality with reservations for jobs, So when you purchase items linked to the job planning line. We want to create a reservation as well. In order to prevent double lines in our requisition sheet when purchasing.

This functionality works when you completely receives the purchases. but incase of partial receipt this reservation entry code does not run for my scenario. so i would like the option to skip or do my own processing with these entries.

Describe the request

local procedure UpdateReservationsWhenPostingJobPlaningLineNegativeAdjFromPO(var JobPlanningLine: Record "Job Planning Line"; var ItemJournalLine: Record "Item Journal Line"; var ReservationEntry: Record "Reservation Entry")
    var
        TempReservationEntry: Record "Reservation Entry" temporary;
        UnitOfMeasureManagement: Codeunit "Unit of Measure Management";
        NewReserveQtyBase: Decimal;
        NewReservationEntryQtyBase: Decimal;
        NewReservationEntryQty: Decimal;
        IsHandled: Boolean;
    begin
        if not ((ItemJournalLine."Document Type" = ItemJournalLine."Document Type"::"Purchase Receipt") and (ItemJournalLine."Entry Type" = ItemJournalLine."Entry Type"::"Negative Adjmt.")) then
            exit;

        ReservationEntry.SetRange("Reservation Status", ReservationEntry."Reservation Status"::Reservation);
        if ReservationEntry.IsEmpty then
            exit;

        NewReserveQtyBase := JobPlanningLine."Remaining Qty. (Base)";
        ReservationEntry.FindSet();

        if NewReserveQtyBase <= 0 then begin
            repeat
                ReservationEngineMgt.CloseReservEntry(ReservationEntry, false, false);
            until ReservationEntry.Next() = 0;
            exit;
        end;

        repeat
            TempReservationEntry.Init();
            TempReservationEntry := ReservationEntry;
            TempReservationEntry.Insert();
        until ReservationEntry.Next() = 0;

        TempReservationEntry.Reset();
// << new event
         OnBeforeCreateRemainingResEntry(TempReservationEntry,ReservationEntry,NewReserveQtyBase ,Ishandled);
         if Ishandled then
               Exit();
// >> new event
        TempReservationEntry.FindSet();
        repeat
            if NewReserveQtyBase >= -TempReservationEntry."Quantity (Base)" then
                NewReserveQtyBase += TempReservationEntry."Quantity (Base)"
            else
                if NewReserveQtyBase = 0 then
                    ReservationEngineMgt.CloseReservEntry(TempReservationEntry, false, false)
                else begin
                    NewReservationEntryQtyBase := NewReserveQtyBase;
                    NewReserveQtyBase := 0;
                    NewReservationEntryQty := UnitOfMeasureManagement.CalcQtyFromBase(NewReservationEntryQtyBase, TempReservationEntry."Qty. per Unit of Measure");
                    CreateReservEntry.CreateRemainingReservEntry(TempReservationEntry, NewReservationEntryQty, NewReservationEntryQtyBase);
                    ReservationEngineMgt.CloseReservEntry(TempReservationEntry, false, false);
                end;
        until TempReservationEntry.Next() = 0;
    end;
 [IntegrationEvent(false, false)]
    local procedure OnBeforeCreateRemainingResEntry(var TempReservationEntry: Record "Reservation Entry" temporary; ReservationEntry: Record "Reservation Entry"; NewReserveQtyBase: Decimal; var IsHandled: Boolean)
    begin
    end;
  1. Problem statement: See above
  2. Proposed code change: See above
  3. Invocation example: IP
  4. Alternatives evaluated: There are no events present in the functions before this or in the function itself.
  5. Justification for IsHandled: Because we have to update the entries and under certain conditions we want to change the reservations. The code as standard has no option to redesign or change this at this point in time.
  6. Performance considerations: No impact, we want to change what entries need to be processed. And will run the same code to Close the entry and create the remaining entry in the same way the already excising code does.
  7. Data sensitivity review: I Confirm that the event does not expose sensitive or securityΓÇærelevant data.
  8. MultiΓÇæextension interaction: Entries will still be processed, We will only change specific entries who are relevant to our solution. In all other scenario's we will follow the default execution.

Internal work item: AB#605579

JellebBE avatar Sep 24 '25 14:09 JellebBE

Hello @JellebBE Recently we announced that for every new IsHandled event request, author need to provide a response to several question (please check link)

We want to be sure that IsHandled event is the only option, as this kind of events is not the best approach due to several reasons (codebase harder to maintain, harder refactoring, fragile solutions, easily break other implementations...)

Please also check the explanation about when and how to use IsHandled events (link)

AleksandricMarko avatar Sep 25 '25 07:09 AleksandricMarko

After you update the request, please reopen it.

AleksandricMarko avatar Sep 25 '25 07:09 AleksandricMarko

@AleksandricMarko i've added the asked information. However i do not have permissions to reopen the issue.

When creating this issue i've followed this page: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/create-extensibility-request Maybe you could suggest that they add a reference to this change in process.

JellebBE avatar Sep 25 '25 08:09 JellebBE

Hello @JellebBE Could you explain me a bit more, why regular event can`t be used here For example, after temp lines are created you can have regular event where you can do whatever you want with temp entries before further processing

Image

AleksandricMarko avatar Dec 02 '25 10:12 AleksandricMarko

Hi @AleksandricMarko

edit: After reading again, your suggestion might work as well.

JellebBE avatar Dec 02 '25 10:12 JellebBE

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

JesperSchulz avatar Dec 03 '25 12:12 JesperSchulz