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

Clean up your copied environments

Clean up your copied environments

One of the most important things every developer should handle is to clean up the environment when the environment (or a company) is copied. Especially if the environment is managed directly by a client and they can create new copies anytime. Similarly, for copied...

read more
7 git commands you should know

7 git commands you should know

For many years, developers in C/AL did not need to know anything about Git or other versioning tools. That has changed with Business Central, or more specifically with AL Language. Today, we will look at the most important (and basic) git commands any developer should...

read more
NavigationAction for ErrorInfo data type

NavigationAction for ErrorInfo data type

One more article about ErrorInfo data type. Have you already read my previous posts about ErrorInfo and Collectible Errors? ErrorInfo data type & Collectible Errors | MSDyn365 Business Central - Ing. Tomáš Kapitán (kepty.cz) Collectible Errors?! | MSDyn365...

read more
Error actions for ErrorInfo data type

Error actions for ErrorInfo data type

It is already almost one and a half years since the ErrorInfo data type was introduced (we saw this data type for the first time in BC2021w2). If you do not know what it is and how to use this data type, check my previous posts: ErrorInfo data type & Collectible...

read more
Data types under the microscope: List

Data types under the microscope: List

The List data type in AL language represents an ordered collection of objects that can be accessed by their index. Unlike an Array data type, a List does not have a fixed size and does not need to have its dimension specified when it is declared. The List data type...

read more
Connect to Azure Function in BC 2022 wave 2 (v21)

Connect to Azure Function in BC 2022 wave 2 (v21)

The new version of the Microsoft Dynamics 365 Business Central brought a new system module "Azure Functions" that makes integration with Azure Functions much easier and straightforward. The typical scenario, why to use Azure Functions together with Business Central,...

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