web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Making a form field mandatory

(0) ShareShare
ReportReport
Posted on by

I have set the Mandatory property for a form field to Yes and the field is underlined in red accordingly to indicate that it must be filled in but on record creation I am able to Close/Esc and the record will save without prompting for the mandatory fields:

mandatory1.JPG

mandatory2.JPG

What have I missed?

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at
    RE: Making a form field mandatory

    I will work on those useful suggestions.

    It is annoying that just setting the Mandatory property does not work consistently. It works elsewhere.

  • Verified answer
    Brandon Wiese Profile Picture
    17,788 on at
    RE: Making a form field mandatory

    The validateWrite() method is called just prior to saving a record from the UX.  If it returns false, the write is aborted.  You can use validateField() and validateFieldValue() also to validate individual fields, but those are only called in response to a field actually changing in the UX, so in your scenario they might not be called at all.

    Since validateWrite() is only called by the UX, a more drastic approach is to check in the write() method itself, and throw an error there on invalid data, since that method does not return a value.  You can also validate data in the .update() and .insert() methods, which would work even outside of the UX, which means it could catch attempts to insert/update invalid data even from X++ code.

  • Community Member Profile Picture
    on at
    RE: Making a form field mandatory

    Thanks, and correct me if I am wrong, but is validateWrite called on record creation when no fields are changed?

  • Suggested answer
    Brandon Wiese Profile Picture
    17,788 on at
    RE: Making a form field mandatory

    This has been an issue for a long time.  It's more common in dialog forms where the field is set mandatory in code.  Ultimately, if your field must contain data, you should check for that in validateWrite() to be certain.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

#1
Guy Terry Profile Picture

Guy Terry 2 Moderator

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans