Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

Setting mandatory field by code is not working as expected

(0) ShareShare
ReportReport
Posted on by 1,550

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);
}

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 292,031 Super User 2025 Season 1 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.

  • Suggested answer
    Komi Siabi Profile Picture
    Komi Siabi 12,759 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

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 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/.../

  • junior AX Profile Picture
    junior AX 1,550 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

  • Komi Siabi Profile Picture
    Komi Siabi 12,759 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.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,031 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,868 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans