Skip to main content

Notifications

Microsoft Dynamics AX forum
Suggested answer

Make Field in Form Mandatory

Posted on by Microsoft Employee

Hi Community,

in my PriceTable I have set the Mandatory Property for ModelId-Field to No.

In my Form Prices, when I set the Fields Vehicle Type and Vehicle Categorie (Except for "Non-Specified", I want the ModelId Field to become Mandatory.

Any Recommendations on how I could do that ?

I thought maybe I write Code in my validateWrite Method of the table, that when those two fields are set, then ModelId has to become mandatory.
But in that case, I heard it is not good on tablelevel to swtich from mandatory No to Yes .

PriceTableMakeModelIdMandatory.PNG

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Make Field in Form Mandatory

    MandatoryFieldInForm.PNG

    Thanks, I addressed the fields just like You said. And it works.

    However, it works that the Model Id field becomes mandatory.

    Also for records I had entered earlier and even for the VehicleType "Truck".... which doesn't actually make sense, since it is not part of my if-clause!!

    But how would it be possible, that the ModelId field for past records will not be marked as mandatory ?(as marked in the screenshot)

    And how can I only select that the edited or basically new record I am working on, that that ModelId shall become mandatory if the if-clause happens to be true ?

    If this Approach of mine is not good, will not be made in usual by the AX-Developers and could be handled much easier, and becomes way to complex or confusing please then let me know, so I can become better and efficient.

    Thanks in advance.

  • Suggested answer
    Ajit Profile Picture
    Ajit 8,755 on at
    RE: Make Field in Form Mandatory

    Why don't you use datasource.fieldName like SYCFMPriceTable.SYCFMVehicleCategorie  == value.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Make Field in Form Mandatory

    4571.Form3.PNG

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Make Field in Form Mandatory

    I am having hard time in addressing the fields or basically the formControl.

    if (SYCFMPriceTable_ds.object(fieldNum(SYCFMPriceTable, SYCFMVehicleTyp::Car)))

    it is giving me syntax error! just as for the other field, which is not an enum.

    i(SYCFMPriceTable_ds.object(fieldNum(SYCFMPriceTable, SYCFMVehicleCategorie == "Non-Specified")))

    How do I address those fields in my form correct ?

  • sohaibcheema Profile Picture
    sohaibcheema 46,590 User Group Leader on at
    RE: Make Field in Form Mandatory

    You may solve this issue in two steps

    1) implement condition on active() method of form data-source

    If(Vehicle Type and Vehicle Categories)

    {

     //Set any field mandatory

    }

    else

    {

    //set non-mandatory

    }

    2) implement same logic on table ValidatWrite()

    Step#2 will make sure that data entry from table level gets correct.

    Please note that if you are using any data entity for DIXF, you would need to see how you want to handle the situation with use of DIXF  

Helpful resources

Quick Links

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Blog subscriptions now enabled!

Follow your favorite blogs

TechTalk: How Dataverse and Microsoft Fabric powers ...

Explore the latest advancements in data export and integration within ...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 283,682 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,000 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,146

Featured topics

Product updates

Dynamics 365 release plans