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 :
Finance | Project Operations, Human Resources, ...
Answered

Validate field Question

(0) ShareShare
ReportReport
Posted on by 30

Hello experts,

i’m following a book to practice x++.

there is a line of code which makes me confused.

can you please help me explain that

DED48460_2D00_864D_2D00_43E0_2D00_A16A_2D00_75D281FA1932.jpeg

While ret get true or false, why author set case with field id?

What if ret is true and the field id is 10? Does it bypass the switch code and continue allowed to enter record?

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    ValidateField method is always called when user changes a field value on a form.

    The FieldId is used to tell this method what field was changed, because only that one field must be checked.

    If _fieldIdToCheck is something else than fieldId of ConWHSVehicleTable.AcquiredDate, the logic inside the case will not be executed. The switch code is never bypassed. Only cases inside it.

    If the validation fails, user must try to enter something else to the field before the validation can pass. The record can be saved only after the validation passes.

    Another place where you can put such validations is validateWrite. There the whole record is always validated. ValidateWrite is always executed before data is saved on a form.

  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Ah, but actually there is a bug in the code. The switch should get "_fieldIdToCheck" as parameter, not "ret".

    Currently it will never reach any case inside your switch statement.

  • RossDo Profile Picture
    30 on at

    Ah it’s great! It makes more sense now.

    Seems author means _fieldIdToCheck not ret.

    Thanks Nikolaos

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 663 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 540 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 348 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans