Skip to main content

Notifications

Announcements

No record found.

Business Central forum

AL: How to add custom validation to a field?

Posted on by 150

Is there a way to make field validation use custom logic? For example, instead of something simple like requiring any numeric value, it might check the value in another table, check for a specific value, etc.

Categories:
  • I Gusti Made Ari Profile Picture
    I Gusti Made Ari 3,594 on at
    RE: AL: How to add custom validation to a field?

    For that , it can only use an expression for the ShowMandatory property, the property cannot validate a C/AL function. So in this case you cannot put logic to check value from other table.

    detail :

    docs.microsoft.com/.../showmandatory-property

    alternatively is use the method i mentioned and pop up Error Message Box .

  • SSDev1 Profile Picture
    SSDev1 150 on at
    RE: AL: How to add custom validation to a field?

    I mean more on a custom page field I have, For example:

    temp.png

    Is it possible to use logic here, test the inputted value, and return true/false? Returning false would display the red X with the reason why it's not valid.

  • I Gusti Made Ari Profile Picture
    I Gusti Made Ari 3,594 on at
    RE: AL: How to add custom validation to a field?

    You can use event subscriber by subscribing to the field you want to validate.

    sample below will do validation on Location Code field at Sales Line table

    [EventSubscriber(ObjectType::Table,37, 'OnAfterValidateEvent', 'Location Code', false, false)]
    local procedure OnValidateLocationCode(var Rec : Record "Sales Line";var xRec : Record "Sales Line";CurrFieldNo : Integer)
    begin
    //Put your custom Logic Here
    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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans