var CustLedgEntry: Record "Cust. Ledger Entry"; ApplyingCustLedgEntry: Record "Cust. Ledger Entry"; CustEntrySetApplID: Codeunit "Cust. Entry-SetAppl.ID"; CustEntryApplyPostedEntries: Codeunit "CustEntry-Apply Posted Entries"; begin CustLedgEntry.SetRange("Entry No.", 144); ApplyingCustLedgEntry.SetRange("Entry No.", 157); CustLedgEntry.Validate("Amount to Apply", -25); ApplyingCustLedgEntry.Validate("Applies-to ID", 'TEST1234'); ApplyingCustLedgEntry.VALIDATE("Amount to Apply", 25); CustEntrySetApplID.SetApplId(CustLedgEntry, ApplyingCustLedgEntry, 'test1234'); ApplyingCustLedgEntry.VALIDATE("Amount to Apply", 25); ApplyingCustLedgEntry.MODIFY(true); CustEntryApplyPostedEntries.Apply(ApplyingCustLedgEntry, ApplyingCustLedgEntry."Document No.", CustLedgEntry."Posting Date"); end;
if ((CustLedgerEntry."Amount to Apply" <> 0) and (CustEntryApplID = '')) or (CustEntryApplID = '') then CustLedgerEntry."Amount to Apply" := [b]ApplyingCustLedgerEntry."Amount to Apply" * -1[/b]//-1//original 0 else if CustLedgerEntry."Amount to Apply" = 0 then begin CustLedgerEntry.CalcFields("Remaining Amount"); CustLedgerEntry."Amount to Apply" := [b]ApplyingCustLedgerEntry."Amount to Apply" * -1[/b];//original CustLedgerEntry."Remaining Amount" end;
Answers
So you want to override "amount to apply" field.
Why dont you create an event subscriber to onaftervalidate for that field?
not sure if I understand what do you want to do.
if you would need to split a payment between several documents proportionally, then you would need to set applies to ID and amount to apply in customer ledger entry/vendor ledger entry.
I think it's codeunits 226/227 that will allow you to edit both tables.
just follow the code in nav standard, I've done this a lot years ago but I dont recall precisely.
hoe this helps.