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;