Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

Prevent posting of Sales Invoice for Customers having balance Overdue

Posted on by 950

I want to  prevent users for generating Sales Invoice for Customers having overdue balance AND where Due Date + 30D < Today's Date.

Hence, the following code was written in Table 36 Sales Header under the trigger Sell-To Customer No - OnValidae:

IF "Document Type" = "Document Type"::Invoice THEN BEGIN

CustLedgEntry.SETCURRENTKEY("Customer No.", Open, "Due Date");
CustLedgEntry.GET("Bill-to Customer No.");
DueDate:= CALCDATE('<30D>', CustLedgEntry."Due Date");
IF (CustLedgEntry.Open = CustLedgEntry.Open::"1") AND
(DueDate < TODAY())
THEN
ERROR('Customer has Overdue amount')
END;

However, I'm getting the following error when adding a customer with overdue balance in Sales Invoice:

Can anyone inform what was wrong on the code.  Thanks

*This post is locked for comments

  • Verified answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: Prevent posting of Sales Invoice for Customers having balance Overdue

    Your statement IF CustLedgEntry.Open is incorrect it is not an option field it is a boolean field.

    One other thing you to calculate overdue balance there is already a function in the customer table called CalcOverDueBalance you can use that  Or create a new function using below logic changing your Due Date Logic compare to your calculated Due instead of work date.

    PROCEDURE CalcOverDueBalance@1100() OverDueBalance : Decimal;
    VAR
    CustLedgerEntry@1102 : Record 21;
    BEGIN
    CustLedgerEntry.SETCURRENTKEY("Customer No.",Open,Positive,"Due Date","Currency Code");
    CustLedgerEntry.SETRANGE("Customer No.","No.");
    CustLedgerEntry.SETRANGE(Open,TRUE);
    CustLedgerEntry.SETFILTER("Due Date",'<%1',WORKDATE); // Change this
    IF CustLedgerEntry.FINDSET THEN
    REPEAT
    CustLedgerEntry.CALCFIELDS("Remaining Amt. (LCY)");
    OverDueBalance += CustLedgerEntry."Remaining Amt. (LCY)";
    UNTIL CustLedgerEntry.NEXT = 0;
    END;

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans