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 :
Microsoft Dynamics AX (Archived)

Make a mandatory Field to not mandatory via Code

(0) ShareShare
ReportReport
Posted on by

Hi Community,

I have table "VehicleModelsTable" .

I have the Fields ManufacturerId, ModelId, VehicleCategorie and VehicleType.

All Fields are set as Mandatory in my Table/Fields/Properties.

For the case I choose Vehicle Categorie as "Non-Specified" I want the fields ManufacturerId and ModelId to not be mandatory anymore.

Is there a way I can write Code in TableMethods for that ? Or do i have to this Code wrting in Forms ?

Thanks in advance.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Muthusamy Profile Picture
    4 on at

    Hi Khasayar,

    You can validate those fields either by using table methods or form methods.

    In table methods, write the code in ValidateWrite method - if fields is not entered with any value means, system will throw the error.

    e.g. if (!this.FieldName)

          {

                ret = checkfailed("Field must be filled in");

          }

    otherwise, you can write the same code in form validatewrite methods by using DS name.

    if you want to make the field as mandatory means (red color underline indication in form), based on certain condition - you can go through by form methods.

    Thanks,

  • Community Member Profile Picture
    on at

    Hi,

    I wrote in my validateWrite() of my Table "PriceTable"

     

        switch (ret)
        {
            case this.Price <= 1.00:
                ret = checkFailed("+++ValidateWrite Method+++" + "@SYC234");
                break;
                
            case this.VehicleCategorie != "Non-Specified":
                
        }


    How shall I Code further ?
    Basically I would suggest, I should then call the Method of my Form, right ? (after case this.VehicleCategorier....)

    Or Shall I immeadiately start coding in my Form, but which Method should I use or where shall I start ?

    Thanks in advance

  • Verified answer
    Heinz Schweda Profile Picture
    1,367 on at

    Hi, if your fields are marked as mandatory on table, you have to enter values.

    You cannot overwrite this validation through code.

    You have to set the Mandatory-property to NO and do all you validation through code. I think the validateWrite() on table is the right place for doing this. Placing this validation on validateWrite() in form is also possible, but should not be the prefered solution (because if someone creates another form with the same datasource, this validation will miss).

    Regards

    Heinz

  • Douglas Noel Profile Picture
    3,905 on at

    Hi,

    you can do a lot of things in validateField and playing with the mandatory property on the control.

    But. If it isn't changed in the meanwhile, please consider that a validateWrite on table level will also check the mandatories.

    Think it's not trivial to de-mandatory a field.

    Regards Douglas

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans