web
You’re offline. This is a read only version of the page.
close
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 6

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

I have the same question (0)
  • Suggested answer
    Binesh Profile Picture
    7,885 on at

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans