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

Notifications

Announcements

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,284 Super User 2025 Season 2 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

News and Announcements

Season of Giving Solutions is Here!

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 > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,703

#2
YUN ZHU Profile Picture

YUN ZHU 803 Super User 2025 Season 2

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 750 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans