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

Setting mandatory field by code is not working as expected

(0) ShareShare
ReportReport
Posted on by 1,552

Hi,

When i set a field as mandatory by code, the red star appears but it still allows me to save without it being filled

if(//)
{
Field1.mandatory(true);
}
else
{
Field1.mandatory(false);
}

I have the same question (0)
  • Komi Siabi Profile Picture
    13,089 Most Valuable Professional on at
    RE: Setting mandatory field by code is not working as expected

    Are you this on a table extension or your custom table ?

    Share the actual code with us.

  • junior AX Profile Picture
    1,552 on at
    RE: Setting mandatory field by code is not working as expected

    Hi Komi,

    This is on a form and field1 is a control with lookup but it's not bound to any datasource

  • Suggested answer
    Mohit Rampal Profile Picture
    12,565 Moderator on at
    RE: Setting mandatory field by code is not working as expected

    Hi, I think unbound fields cannot be changed to mandatory. Even though it will show red line and feels it is mandatory but it's not.

    There is a feature to make field required by personalization but won't recommend if required for all users as user can disable it and moreover personalizationn has to be used by all users.

    dynamicspedia.com/.../

  • Suggested answer
    Komi Siabi Profile Picture
    13,089 Most Valuable Professional on at
    RE: Setting mandatory field by code is not working as expected

    Hello Junior AX,

    Just like Mohit said, I doubt you will get the result using .mandatory.

    You check if the field is empty and throw an error yourself. 

    Check this.

    community.dynamics.com/.../want-to-mandatory-display-unbound-field

  • André Arnaud de Calavon Profile Picture
    300,716 Super User 2025 Season 2 on at
    RE: Setting mandatory field by code is not working as expected

    Hi junior AX,

    A small addition to the comments above. Mohit shared my blog. Also, the option described in this blog is not working for unbound controls.

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 683 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 398 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans