[Event Request] codeunit 12 "Gen. Jnl.-Post Line" - New event publisher within the PostApply procedure
Why do you need this change?
When subscribing to the current event OnAfterFindAmtForAppln in the FindAmtForAppln procedure in codeunit "Gen. Jnl.-Post Line", the code in the subscriber will not execute if another extension sets the IsHandled variable in the OnBeforeFindAmtForAppln event.
To address this, we should introduce an event publisher within the PostApply procedure, which is invoked immediately after the FindAmtForAppl procedure, e.g. "OnAfterFindAmtForApplnOnBeforeCalcCurrencyUnrealizedGainLoss". This event allows us to utilize the calculated variables from the FindAmtForAppln procedure, even if they are calculated by another extension and the IsHandled variable was set.
Describe the request
Current Version
procedure PostApply(var GenJnlLine: Record "Gen. Journal Line"; var DtldCVLedgEntryBuf: Record "Detailed CV Ledg. Entry Buffer"; var OldCVLedgEntryBuf: Record "CV Ledger Entry Buffer"; var NewCVLedgEntryBuf: Record "CV Ledger Entry Buffer"; var NewCVLedgEntryBuf2: Record "CV Ledger Entry Buffer"; BlockPaymentTolerance: Boolean; AllApplied: Boolean; var AppliedAmount: Decimal; var PmtTolAmtToBeApplied: Decimal)
var
OldCVLedgEntryBuf2: Record "CV Ledger Entry Buffer";
OldCVLedgEntryBuf3: Record "CV Ledger Entry Buffer";
OldRemainingAmtBeforeAppln: Decimal;
ApplnRoundingPrecision: Decimal;
AppliedAmountLCY: Decimal;
OldAppliedAmount: Decimal;
IsHandled: Boolean;
begin
...
if not IsHandled then begin
FindAmtForAppln(
NewCVLedgEntryBuf, OldCVLedgEntryBuf, OldCVLedgEntryBuf2,
AppliedAmount, AppliedAmountLCY, OldAppliedAmount, ApplnRoundingPrecision, GenJnlLine);
CalcCurrencyUnrealizedGainLoss(
OldCVLedgEntryBuf, DtldCVLedgEntryBuf, GenJnlLine, -OldAppliedAmount, OldRemainingAmtBeforeAppln);
CalcCurrencyRealizedGainLoss(
NewCVLedgEntryBuf, DtldCVLedgEntryBuf, GenJnlLine, AppliedAmount, AppliedAmountLCY);
CalcCurrencyRealizedGainLoss(
OldCVLedgEntryBuf, DtldCVLedgEntryBuf, GenJnlLine, -OldAppliedAmount, -AppliedAmountLCY);
CalcApplication(
NewCVLedgEntryBuf, OldCVLedgEntryBuf, DtldCVLedgEntryBuf,
GenJnlLine, AppliedAmount, AppliedAmountLCY, OldAppliedAmount,
NewCVLedgEntryBuf2, OldCVLedgEntryBuf3, AllApplied);
PaymentToleranceMgt.CalcRemainingPmtDisc(NewCVLedgEntryBuf, OldCVLedgEntryBuf, OldCVLedgEntryBuf2, GLSetup);
CalcAmtLCYAdjustment(OldCVLedgEntryBuf, DtldCVLedgEntryBuf, GenJnlLine);
end;
OnAfterPostApply(GenJnlLine, DtldCVLedgEntryBuf, OldCVLedgEntryBuf, NewCVLedgEntryBuf, NewCVLedgEntryBuf2);
end;
Request
procedure PostApply(var GenJnlLine: Record "Gen. Journal Line"; var DtldCVLedgEntryBuf: Record "Detailed CV Ledg. Entry Buffer"; var OldCVLedgEntryBuf: Record "CV Ledger Entry Buffer"; var NewCVLedgEntryBuf: Record "CV Ledger Entry Buffer"; var NewCVLedgEntryBuf2: Record "CV Ledger Entry Buffer"; BlockPaymentTolerance: Boolean; AllApplied: Boolean; var AppliedAmount: Decimal; var PmtTolAmtToBeApplied: Decimal)
var
OldCVLedgEntryBuf2: Record "CV Ledger Entry Buffer";
OldCVLedgEntryBuf3: Record "CV Ledger Entry Buffer";
OldRemainingAmtBeforeAppln: Decimal;
ApplnRoundingPrecision: Decimal;
AppliedAmountLCY: Decimal;
OldAppliedAmount: Decimal;
IsHandled: Boolean;
begin
...
if not IsHandled then begin
FindAmtForAppln(
NewCVLedgEntryBuf, OldCVLedgEntryBuf, OldCVLedgEntryBuf2,
AppliedAmount, AppliedAmountLCY, OldAppliedAmount, ApplnRoundingPrecision, GenJnlLine);
// - new event publisher called ---
OnAfterFindAmtForApplnOnBeforeCalcCurrencyUnrealizedGainLoss(
NewCVLedgEntryBuf, OldCVLedgEntryBuf, OldCVLedgEntryBuf2, AppliedAmount,
AppliedAmountLCY, OldAppliedAmount, AmountRoundingPrecision, VATEntry);
// + new event publisher called +++
CalcCurrencyUnrealizedGainLoss(
OldCVLedgEntryBuf, DtldCVLedgEntryBuf, GenJnlLine, -OldAppliedAmount, OldRemainingAmtBeforeAppln);
CalcCurrencyRealizedGainLoss(
NewCVLedgEntryBuf, DtldCVLedgEntryBuf, GenJnlLine, AppliedAmount, AppliedAmountLCY);
CalcCurrencyRealizedGainLoss(
OldCVLedgEntryBuf, DtldCVLedgEntryBuf, GenJnlLine, -OldAppliedAmount, -AppliedAmountLCY);
CalcApplication(
NewCVLedgEntryBuf, OldCVLedgEntryBuf, DtldCVLedgEntryBuf,
GenJnlLine, AppliedAmount, AppliedAmountLCY, OldAppliedAmount,
NewCVLedgEntryBuf2, OldCVLedgEntryBuf3, AllApplied);
PaymentToleranceMgt.CalcRemainingPmtDisc(NewCVLedgEntryBuf, OldCVLedgEntryBuf, OldCVLedgEntryBuf2, GLSetup);
CalcAmtLCYAdjustment(OldCVLedgEntryBuf, DtldCVLedgEntryBuf, GenJnlLine);
end;
OnAfterPostApply(GenJnlLine, DtldCVLedgEntryBuf, OldCVLedgEntryBuf, NewCVLedgEntryBuf, NewCVLedgEntryBuf2);
end;
// - new event publisher ---
[IntegrationEvent(false, false)]
local procedure OnAfterFindAmtForApplnOnBeforeCalcCurrencyUnrealizedGainLoss(var NewCVLedgEntryBuf: Record "CV Ledger Entry Buffer"; var OldCVLedgEntryBuf: Record "CV Ledger Entry Buffer"; var OldCVLedgEntryBuf2: Record "CV Ledger Entry Buffer"; var AppliedAmount: Decimal; var AppliedAmountLCY: Decimal; var OldAppliedAmount: Decimal; var ApplnRoundingPrecision: Decimal; var VATEntry: Record "VAT Entry")
begin
end;
// + new event publisher +++
Internal work item: AB#582289
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: 36295.
Availability update: We will publish a fix for this issue in the next update for release 26.
Build ID to track: 36526.