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 :
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

I have the same question (0)
  • Verified answer
    Teddy Herryanto (That NAV Guy) Profile Picture
    14,284 Super User 2025 Season 2 on at

    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

  • Suggested answer
    YUN ZHU Profile Picture
    95,391 Super User 2025 Season 2 on at

    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

  • RM-30091108-0 Profile Picture
    3 on at
    @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?

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,990

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,576 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,028 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans