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 :
Business Central forum

AL: How to add custom validation to a field?

(0) ShareShare
ReportReport
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 have the same question (0)
  • I Gusti Made Ari Profile Picture
    3,600 on at

    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;
  • SSDev1 Profile Picture
    150 on at

    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
    3,600 on at

    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 .

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 > Business Central

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans