web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Incorrect validation error thrown

(0) ShareShare
ReportReport
Posted on by 700

Hi All,

On a page, there are two fields - 'From Date' and 'To Date'.

Whenever  'From Date' is filled and 'To Date' is made empty after filling a value, then wrong validation error is thrown.

How to overcome this ?

Below is the AL code -

field(50103; FromDate; Date)
        {
            DataClassification = ToBeClassified;
            Caption = 'From Date';
            NotBlank = true;

          
            trigger OnValidate()
            var
                myInt: Integer;
            begin
                if (No_Series = ''then    // *** added for autopopulate series 
                    No_Series := 'JDCODE';
            end;
        }
        field(50104; ToDate; Date)
        {
            DataClassification = ToBeClassified;
            Caption = 'To Date';
            NotBlank = true;
            trigger OnValidate()
            begin

                begin
                    if (No_Series = ''then    // *** added for autopopulate series 
                        No_Series := 'JDCODE';
                end;
            


                IF ("FromDate" > "ToDate"then
                    Error('Cannot be earlier than "From Date"');
                
            end;
        }
Please suggest !
I have the same question (0)
  • Suggested answer
    Teddy Herryanto (That NAV Guy) Profile Picture
    14,300 Super User 2026 Season 1 on at

    Error('Cannot be earlier than %1',FromDate);

  • Dynamics 365 Business Central Profile Picture
    700 on at

    Hi Teddy,

    Thanks for your response.

    But, actually I asked for the code logic.

    Requirement is

    1. When To Date is less, then error should be displayed

    2. When From Date is filled but To Date is empty, then error should be displayed

    3. When To Date is filled but From Date is empty, then error should be displayed

    This is what I want to achieve.

  • Suggested answer
    Community Member Profile Picture
    on at

    IF (("FromDate" <> 0D) and ("ToDate" <>0D)) and  ("FromDate" > "ToDate") then

    Error('Cannot be earlier than %1',FromDate);

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,870 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,138 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 915 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans