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 :
Small and medium business | Business Central, N...
Suggested Answer

Issue with ShowMandatory = true Property for Enum Fields in Business Central

(6) ShareShare
ReportReport
Posted on by 12

Dear Dynamics Community,

I am currently attempting to use the page property ShowMandatory = true to mark an enum field as required on a page. While this property functions correctly for fields of type Code, it does not appear to have any effect when applied to enum fields.

Is there a known limitation regarding the use of ShowMandatory with enum field types? If so, I would greatly appreciate any suggestions or workarounds to achieve similar functionality for enum fields.

Thank you in advance for your support and guidance.

I have the same question (0)
  • Teagen Boll Profile Picture
    663 on at
    That might be tricky because ShowMandatory is just looking to see if a field isn't blank then displaying a red asterisk.
     
    You could try using the property NotBlank instead and it will also add the red asterisk and also validate the field. You could then try having one value be None like this:
    enum 50121 Loyalty
    {
        Extensible = true;
        
        value(0; None) { }
        value(1; Bronze) { }
        value(2; Silver) { }
        value(3; Gold)
        {
            Caption = 'Gold Customer';
        }
    }
     
    Then try using either ShowMandatory or NotBlank to see if that flags it as mandatory/validates the field.
  • Suggested answer
    Gregory Mavrogeorgis Profile Picture
    763 on at
    Hi,
     
    Yep—this is (kinda) a limitation. ShowMandatory only shows the red asterisk if a field can be blank. Enums always have a value (default = first member), so nothing to flag.
    Easy workaround:
    • Add a “Not set” enum value (make it the first).
    • Bind the asterisk to a boolean/expression:
    • ShowMandatory = (Rec."My Status" = Rec."My Status"::"Not set");
    • Enforce server-side so users can’t save “Not set”:
    • if Rec."My Status" = Rec."My Status"::"Not set" then
    •     Error('%1 is required.', FieldCaption("My Status"));
    Can’t change the enum? Use a page variable to drive ShowMandatory with your own logic, and keep the table validation.
     
    If you found this helpful please mark it as verified
  • Suggested answer
    Teddy Herryanto (That NAV Guy) Profile Picture
    14,284 Super User 2025 Season 2 on at
    ShowMandatory doesn't work with Enum.
    What you can do is set the 0 caption as something like "Must select one".
     
    Then add a code somewhere to validate it, such as OnInsert or OnModify.
  • Suggested answer
    Jainam M. Kothari Profile Picture
    15,627 Super User 2025 Season 2 on at
  • Suggested answer
    Valentin Castravet Profile Picture
    31,262 Super User 2025 Season 2 on at

    It can work like this: most enum fields aren’t blank by default, so to use ShowMandatory include a blank option. Set both ShowMandatory and BlankZero on the field.

    For example, in the field below I set the enum’s value(0) caption to a single space and then set both ShowMandatory and BlankZero to true:
     
     
     
  • Suggested answer
    YUN ZHU Profile Picture
    95,309 Super User 2025 Season 2 on at
    Hi, hope the following helps.
    Dynamics 365 Business Central: The red asterisk next to a field (mandatory field???)
     
    Thanks.
    ZHU
  • Suggested answer
    OussamaSabbouh Profile Picture
    5,078 on at
    Hello,
     
    Yes — ShowMandatory doesn’t highlight enum fields because enums always have a value (their default option).
    To mimic required behavior:
     
    Add a blank/“<Select>” value in the enum.
     
    Use StyleExpr or OnValidate to flag or block when it’s still “<Select>”.
     
    Regards,
    Oussama Sabbouh
  • Suggested answer
    Aman Kakkar Profile Picture
    2,241 on at
    Hi,
     
    You can achieve this via writing below mentioned code snippets.
     
    STEP 01 - Add a blank value at index 0 in your enum definition. This allows the field to appear empty until a valid selection is made.
     
    enum 50010 Test
    {
        Extensible = true;
    
        value(0; "") { }
        value(1; Test01) { }
        value(2; Test02) { }
        value(3; Test03) { }
    }
    STEP 02 - On your page field, set the following properties:
     
    field("Test Enum"; Rec."Test Enum")
    {
        ShowMandatory = true;
        BlankZero = true;
    }
     
    Now the enum field will behave like a required field (ShowMandatory = true) — showing the red asterisk and prompting the user to select a valid value other than the blank one.
     
     
    Do mark as verified if this helps.
    Aman K
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    20,234 Super User 2025 Season 2 on at

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 > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,175

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 2,476 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,435 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans