Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

AL Field Validations: TestField vs Validate

(0) ShareShare
ReportReport
Posted on by 73

Hi all,

I'm working through different filed methods and came across the documentation highlighting two different validation options for fields in AL, TestField, and Validate

What are the differences between using these two, and which scenarios work best for each case?

It seems both can see if a record exists or doesn't have a value.

You can also check to see if a record meets criteria with seemingly the same syntax?

pastedimage1677781121445v1.png

pastedimage1677781138113v2.png

  • RM-30091108-0 Profile Picture
    3 on at
    AL Field Validations: TestField vs Validate
    @YUN ZHU, how do you display the red field error icon and red border on a field in a validation procedure? FieldError does not.
     
    Like this?
  • Suggested answer
    YUN ZHU Profile Picture
    82,747 Super User 2025 Season 1 on at
    RE: AL Field Validations: TestField vs Validate

    Hi, just adding some info.

    In fact, there is Record.FieldError(Any [, String]) Method, you can also try.

    Record.FieldError(Any [, String]) Method - Business Central | Microsoft Learn

    pastedimage1677817764520v1.png

    Hope this helps as well.

    Thanks.

    ZHU

  • Verified answer
    Teddy Herryanto (That NAV Guy) Profile Picture
    13,637 Moderator on at
    RE: AL Field Validations: TestField vs Validate

    TestField and Validate are two different things.

    TestField is to test whether the value of the field is what you want. On your example: Testing if the Customer Salesperson Code is ZX. If it is not ZX, it will throw an error.

    Validation runs any validation logic on the OnValidate trigger of the field. If there is nothing on OnValidate trigger, there will be no error. In general, you should always runs the Validation.

    You can have testfield inside OnValidate trigger. Example:

    Customer.Validate("Phone No.", '1234567891234');

    field(9; "Phone No."; Text[30])

    {

       trigger OnValidate()

       begin

           if Rec."Phone No." <> '' then

             Rec.TestField("Salesperson Code",'ZX'); //meaning that you can only input Phone No if Salesperson is ZX

       end;

    }

    TestField reference.

    learn.microsoft.com/.../testfield-function--record-

    Validate reference.

    learn.microsoft.com/.../record-validate-method

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 Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

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

#1
YUN ZHU Profile Picture

YUN ZHU 448 Super User 2025 Season 1

#2
Sagar Dangar, MCP Profile Picture

Sagar Dangar, MCP 358

#3
Mansi Soni Profile Picture

Mansi Soni 327

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans