Skip to main content

Notifications

Announcements

No record found.

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

Customer Name validation AL

(0) ShareShare
ReportReport
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,194 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans