Skip to main content

Notifications

Small and medium business | Business Central, N...
Answered

Customer Name validation AL

Posted on by

Hi all,

I need to validate customer name during creation of a new customer such that the creator must enter at least two strings i.e., you should not enter one name but at least two separated by a space.

How can I achieve this in OnAfterValidate or OnBeforeValidate trigger?

  • Suggested answer
    sVerme Profile Picture
    sVerme 120 on at
    RE: Customer Name validation AL

    Hi Romryan,

    have a look at String Functions.

    You could use strpos to get the position of a space, and then check if it's not at the first or last index of the string. (maxstrlen)

  • Verified answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,077 Super User 2024 Season 2 on at
    RE: Customer Name validation AL

    You can try the below code

      [EventSubscriber(ObjectType::Table, Database::Customer, 'OnAfterValidateEvent', 'Name', false, false)]

       local procedure OnAfterValidateEventName(var Rec: Record Customer; var xRec: Record Customer; CurrFieldNo: Integer)

       var

           SpacePos: Integer;

       begin

           SpacePos := StrPos(Rec.Name, ' ');

           if SpacePos > 0 then

               if CopyStr(Rec.Name, SpacePos + 1, MaxStrLen(Rec.Name)) <> '' then

                   exit;

           Error('Please enter name with a space.');

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 Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

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,113 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,918 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans