How to define the source for item reservations?

by May 17, 2023AL Language

Home 9 Development 9 AL Language 9 How to define the source for item reservations?

It’s not uncommon to have a customer’s request to limit from which source items could be reserved. For example, customers may not want to reserve items from return orders. How can we achieve this goal?

It’s really simple. All the magic is done in the procedure SetValueArray(…) in codeunit 99000845 “Reservation Management”. As we are interested in reservations only, we need to check the first section – for EntryStatus = 0. As you can see below, there is just a list of all reservation types. The lover array index, the higher priority the source has (for example, ValueArray[1] means that Item Ledger Entry source has the highest priority).

local procedure SetValueArray(EntryStatus: Option Reservation,Tracking,Simulation) ArrayCounter: Integer
var
    IsHandled: Boolean;
begin
    IsHandled := false;
    OnBeforeSetValueArray(EntryStatus, ValueArray, ArrayCounter, IsHandled);
    if not IsHandled then begin
        Clear(ValueArray);
        case EntryStatus of
            0:
                begin // Reservation
                    ValueArray[1] := "Reservation Summary Type"::"Item Ledger Entry".AsInteger();
                    ValueArray[2] := "Reservation Summary Type"::"Sales Order".AsInteger();
                    ValueArray[3] := "Reservation Summary Type"::"Sales Return Order".AsInteger();
                    ValueArray[4] := "Reservation Summary Type"::"Purchase Order".AsInteger();
                    ValueArray[5] := "Reservation Summary Type"::"Purchase Return Order".AsInteger();
                    ValueArray[6] := "Reservation Summary Type"::"Firm Planned Production Order".AsInteger();
                    ValueArray[7] := "Reservation Summary Type"::"Released Production Order".AsInteger();
                    ValueArray[8] := "Reservation Summary Type"::"Firm Planned Prod. Order Comp.".AsInteger();
                    ValueArray[9] := "Reservation Summary Type"::"Released Prod. Order Comp.".AsInteger();
                    ValueArray[10] := "Reservation Summary Type"::"Transfer Shipment".AsInteger();
                    ValueArray[11] := "Reservation Summary Type"::"Transfer Receipt".AsInteger();
                    ValueArray[12] := "Reservation Summary Type"::"Service Order".AsInteger();
                    ValueArray[13] := "Reservation Summary Type"::"Job Planning Order".AsInteger();
                    ValueArray[14] := "Reservation Summary Type"::"Assembly Order Header".AsInteger();
                    ValueArray[15] := "Reservation Summary Type"::"Assembly Order Line".AsInteger();
                    ValueArray[16] := "Reservation Summary Type"::"Inventory Receipt".AsInteger();
                    ValueArray[17] := "Reservation Summary Type"::"Inventory Shipment".AsInteger();
                    ArrayCounter := 17;
                end;
    ...
    ...
end;

So what should we do if we do not want to reserve from return orders? We can just subscribe to OnBeforeSetValueArray(…) publisher and redefine the priorities (or even exclude some of the values). Do not forget to check EntryStatus to verify that you are changing only the reservation, not the rest of the processes.

Also do not forget to update indexes to not have any empty number (otherwise some processes will end with an error) and update ArrayCounter with the number of elements in the array.

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Reservation Management", 'OnBeforeSetValueArray', '', false, false)]
local procedure OnBeforeSetValueArrayReservationManagement(EntryStatus: Option; var ValueArray: array[30] of Integer; var ArrayCounter: Integer; var IsHandled: Boolean)
begin
    if EntryStatus <> 0 then // Reservation
        exit;

    Clear(ValueArray);
    ValueArray[1] := "Reservation Summary Type"::"Item Ledger Entry".AsInteger();
    ValueArray[2] := "Reservation Summary Type"::"Sales Order".AsInteger();
    //ValueArray[3] := "Reservation Summary Type"::"Sales Return Order".AsInteger();
    ValueArray[3] := "Reservation Summary Type"::"Purchase Order".AsInteger();
    //ValueArray[5] := "Reservation Summary Type"::"Purchase Return Order".AsInteger();
    ValueArray[4] := "Reservation Summary Type"::"Firm Planned Production Order".AsInteger();
    ValueArray[5] := "Reservation Summary Type"::"Released Production Order".AsInteger();
    ValueArray[6] := "Reservation Summary Type"::"Firm Planned Prod. Order Comp.".AsInteger();
    ValueArray[7] := "Reservation Summary Type"::"Released Prod. Order Comp.".AsInteger();
    ValueArray[8] := "Reservation Summary Type"::"Transfer Shipment".AsInteger();
    ValueArray[9] := "Reservation Summary Type"::"Transfer Receipt".AsInteger();
    ValueArray[10] := "Reservation Summary Type"::"Service Order".AsInteger();
    ValueArray[11] := "Reservation Summary Type"::"Job Planning Order".AsInteger();
    ValueArray[12] := "Reservation Summary Type"::"Assembly Order Header".AsInteger();
    ValueArray[13] := "Reservation Summary Type"::"Assembly Order Line".AsInteger();
    ValueArray[14] := "Reservation Summary Type"::"Inventory Receipt".AsInteger();
    ValueArray[15] := "Reservation Summary Type"::"Inventory Shipment".AsInteger();
    ArrayCounter := 15;
    IsHandled := true;
end;

Recent Articles from the category

BC Open Source? How to start?

BC Open Source? How to start?

BC Open Source? How to start? One of the most exciting news introduced last month in Lyon during Directions EMEA 2023 was the changes to the open-source initiative. This means that you can now contribute to the source code of the Base app and the System app, which are...

read more
Validate a FlowField Field. Wait? What?

Validate a FlowField Field. Wait? What?

Validate a FlowField Field. Wait? What? There are not many things in the AL Language that surprised me. However, last week, I found one such thing - I reviewed customizations made by another partner and had to analyze the OOTB code of the Demand Forecast matrix. I run...

read more
Dynamics NAV 2013 & Expired Cronus License

Dynamics NAV 2013 & Expired Cronus License

We found an interesting problem - we were not able to run the development environment for Dynamics NAV 2013. Whenever we tried to run the development client, we got the following error message: "Your program license has expired" and the development client has closed...

read more
Indirect Dependencies and Access Modifiers

Indirect Dependencies and Access Modifiers

Last week, there was a discussion on Yammer on how to get values from the "Sent Email" record when all fields are marked as Internal. I was surprised that many people do not know what can/can't access modifiers (such as local, protected, or internal) be used for. I...

read more

Sign Up for News

Certifications

Highest certification
Microsoft Data Management and
also in D365 Business Central

Microsoft Certified: Dynamics 365 Business Central Functional Consultant Associate

See other certifications here