Skip to main content
Microsoft Dynamics NAV forum
Suggested answer

Cust. Ledger Entry get record problem in code Unit/ Close all open payments on button click

editSubscribe (0) ShareShare
ReportReport
Posted on by

Hello Everyone,
I have close all opened payments on one button click. My custom codeunit will check all opened payment records and deduct the payment amount from the sale invoices against the same customer. If sales invoice remaining amount become zero than that sale invoice should close.
I write my custom codeunit to solve this problem but issue is that when i get the record from cust. Ledger Entry table the amount against the customer appears zero.

Name DataType Subtype Length
Cust_led Record Cust. Ledger Entry
CustomerNo Code 20
Amount Decimal

Cust_led.FINDSET;
IF (Cust_led.FIND('-')) THEN REPEAT

IF (Cust_led.Open = TRUE) THEN BEGIN

CASE Cust_led."Document Type" OF
Cust_led."Document Type"::Payment:
BEGIN

CustomerNo := Cust_led."Customer No.";
Amount := Cust_led.Amount;
MESSAGE(FORMAT(Amount));
Cust_led.Open := FALSE;
IF (Cust_led.FIND('-')) THEN REPEAT
IF(Cust_led.Open = TRUE) THEN
IF(Cust_led."Customer No." = CustomerNo) AND (Amount < 0) THEN BEGIN
CASE Cust_led."Document Type" OF
Cust_led."Document Type"::Invoice:
BEGIN
Cust_led."Remaining Amount" := Cust_led."Remaining Amount" + Amount;
IF(Cust_led."Remaining Amount" <= 0) THEN BEGIN
Cust_led.Open := FALSE;
Amount := Cust_led."Remaining Amount";
MESSAGE('Payment apply');
END
END
END
END
UNTIL Cust_led.NEXT = 0;
MESSAGE('Payment Close');
END
END
END
UNTIL Cust_led.NEXT = 0;

I write this custom codeunit. Anyone can guide me where am i doing wrong? or any better approach to solve this task?

  • Suggested answer
    Binesh Profile Picture
    Binesh 7,885 on at
    RE: Cust. Ledger Entry get record problem in code Unit/ Close all open payments on button click

    Hello,

    IF (Cust_led.FIND('-')) THEN REPEAT

    after this statement you have to use calcfields to get the flowfield data for your example write below statement.

     Cust_led.CALCFIELDS(Amount, "Remaining Amount");

Helpful resources

Quick Links

What Motivates a Super User?

We know many of you visit the Dynamics 365 Community and Power Platform…

Demystifying Copilot with Sundar…

Industry experts answer burning questions directly from our amazing Community…

Enabling Copilot Case and Conversation…

Agents can easily recap an ongoing chat, transcribe a voice conversation…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,030 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,562 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Product updates

Dynamics 365 release plans