Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

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

(0) ShareShare
ReportReport
Posted on by 2

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?

*This post is locked for comments

  • Suggested answer
    Binesh Profile Picture
    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");

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,145 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,923 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans