Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Change field's Mandatory property with code

(0) ShareShare
ReportReport
Posted on by

Hello,

I want to set field to mandatory depending on other field. It is working well, the only problem I face is when currently marked row is with value that couse my field to be mandatory. When I just go with the mouse pointer thru same field on the others rows ( I am not clicking on other rows, just point to them) the field changes his mandatory property to true also. If I click on row that should not be mandatory and goes again thru all rows the red line (for mandatory) is gone. I was thinking about something like comment super() in method that respond for moving mouse over the field but I cant find the exact method. Could you suggest anything else?

The code I use is:

public int active()
{

int ret;

ret = super();

if (expression)
{
datesource_ds.object(fieldNum(datesource, RefItemId)).mandatory(false);
datesource_ds.object(fieldNum(datesource, RefItemId)).allowEdit(false);
}
else
{
datesource_ds.object(fieldNum(datesource, RefItemId)).mandatory(true);
datesource_ds.object(fieldNum(datesource, RefItemId)).allowEdit(true);
}

return ret;
}

Thank You!

*This post is locked for comments

  • Jonathan  Halland Profile Picture
    11,306 on at
    RE: Change field's Mandatory property with code

    Hi, just echoing what Andre said, Microsoft tends to use this approach for rule based mandatory requirements in its standard code.

  • Community Member Profile Picture
    on at
    RE: Change field's Mandatory property with code

    I will try this workaround. Thank You !

  • Community Member Profile Picture
    on at
    RE: Change field's Mandatory property with code

    I think you are getting this error because you setting the mandatory and allowEdit property of datasource field object

    Consider setting mandatory and allowEdit property of form grid column text box

    Please verify and update us if this helps you.

  • Suggested answer
    André Arnaud de Calavon Profile Picture
    293,140 Super User 2025 Season 1 on at
    RE: Change field's Mandatory property with code

    Hi,

    I think you can better write some code within the validateWrite method to check if there is a dependency to have a field filled mandatory. Then you don't have to use the code above and it will also prevent saving the record without required fields filled.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,140 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,895 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans