Why do you need this change?
We need to suppress the standard application-loop exit inside ApplyItemLedgEntry when "Remaining Quantity" + "Reserved Quantity" = 0 is satisfied, but an additional quantity dimension on the item ledger entry is still non-zero. The standard code exits unconditionally when that single sum reaches zero, with no way to evaluate further conditions before the exit is taken.
The standard exit check is if ItemLedgEntry."Remaining Quantity" + ItemLedgEntry."Reserved Quantity" = 0 then exit. For items that carry an additional quantity field alongside the base quantity, the base remaining quantity can reach zero while the alternate remaining quantity is still outstanding, meaning the application is not yet complete. The standard check cannot account for this because it reads only the two base fields.
OnAfterUpdateItemLedgerEntryRemainingQuantity fires inside UpdateItemLedgerEntryRemainingQuantity before CalcReservedQuantity is called on the outer entry, so reserved quantity is not yet refreshed and the full exit condition cannot be evaluated there. OnApplyItemLedgEntryOnApplicationLoop fires at the very end of each loop iteration, after the exit check has already been executed and the procedure has already returned, making it too late to prevent the exit. No event currently exists between ItemLedgEntry.CalcReservedQuantity() and the if ... = 0 then exit line inside the if AppliedQty <> 0 then block of ApplyItemLedgEntry.
Describe the request
Add an integration event OnApplyItemLedgEntryOnBeforeCheckApplicationComplete in ApplyItemLedgEntry in Codeunit 22 "Item Jnl.-Post Line" after ItemLedgEntry.CalcReservedQuantity() and before the exit condition that checks whether remaining and reserved quantities sum to zero.
UpdateItemLedgerEntryRemainingQuantity(ItemLedgEntry, AppliedQty, OldItemLedgEntry, CausedByTransfer);
ItemLedgEntry.CalcReservedQuantity();
IsHandled := false;
OnApplyItemLedgEntryOnBeforeCheckApplicationComplete(ItemLedgEntry, IsHandled); // <---- New Event
if not IsHandled then
if ItemLedgEntry."Remaining Quantity" + ItemLedgEntry."Reserved Quantity" = 0 then
exit;
end;
Event Signature:
[IntegrationEvent(false, false)]
local procedure OnApplyItemLedgEntryOnBeforeCheckApplicationComplete(var ItemLedgEntry: Record "Item Ledger Entry"; var IsHandled: Boolean)
begin
end;
Alternatives evaluated: OnAfterUpdateItemLedgerEntryRemainingQuantity fires inside UpdateItemLedgerEntryRemainingQuantity before CalcReservedQuantity is called on the outer item ledger entry, so the reserved quantity used in the exit condition is not yet current and the full exit decision cannot be made at that point. OnApplyItemLedgEntryOnApplicationLoop fires at the very end of each loop iteration, after the exit check has already executed and the procedure has already returned when the condition was true, making it impossible to prevent the exit. No event currently exists between ItemLedgEntry.CalcReservedQuantity() and the if ItemLedgEntry."Remaining Quantity" + ItemLedgEntry."Reserved Quantity" = 0 then exit line inside the if AppliedQty <> 0 then block of ApplyItemLedgEntry.
Internal work item: AB#638497
Why do you need this change?
We need to suppress the standard application-loop exit inside
ApplyItemLedgEntrywhen"Remaining Quantity" + "Reserved Quantity" = 0is satisfied, but an additional quantity dimension on the item ledger entry is still non-zero. The standard code exits unconditionally when that single sum reaches zero, with no way to evaluate further conditions before the exit is taken.The standard exit check is
if ItemLedgEntry."Remaining Quantity" + ItemLedgEntry."Reserved Quantity" = 0 then exit. For items that carry an additional quantity field alongside the base quantity, the base remaining quantity can reach zero while the alternate remaining quantity is still outstanding, meaning the application is not yet complete. The standard check cannot account for this because it reads only the two base fields.OnAfterUpdateItemLedgerEntryRemainingQuantityfires insideUpdateItemLedgerEntryRemainingQuantitybeforeCalcReservedQuantityis called on the outer entry, so reserved quantity is not yet refreshed and the full exit condition cannot be evaluated there.OnApplyItemLedgEntryOnApplicationLoopfires at the very end of each loop iteration, after the exit check has already been executed and the procedure has already returned, making it too late to prevent the exit. No event currently exists betweenItemLedgEntry.CalcReservedQuantity()and theif ... = 0 then exitline inside theif AppliedQty <> 0 thenblock ofApplyItemLedgEntry.Describe the request
Add an integration event
OnApplyItemLedgEntryOnBeforeCheckApplicationCompleteinApplyItemLedgEntryin Codeunit 22 "Item Jnl.-Post Line" afterItemLedgEntry.CalcReservedQuantity()and before the exit condition that checks whether remaining and reserved quantities sum to zero.Event Signature:
Alternatives evaluated: OnAfterUpdateItemLedgerEntryRemainingQuantity fires inside UpdateItemLedgerEntryRemainingQuantity before CalcReservedQuantity is called on the outer item ledger entry, so the reserved quantity used in the exit condition is not yet current and the full exit decision cannot be made at that point. OnApplyItemLedgEntryOnApplicationLoop fires at the very end of each loop iteration, after the exit check has already executed and the procedure has already returned when the condition was true, making it impossible to prevent the exit. No event currently exists between ItemLedgEntry.CalcReservedQuantity() and the if ItemLedgEntry."Remaining Quantity" + ItemLedgEntry."Reserved Quantity" = 0 then exit line inside the if AppliedQty <> 0 then block of ApplyItemLedgEntry.
Internal work item: AB#638497