web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
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

I have the same question (0)
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    306,430 Super User 2026 Season 1 on at

    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.

  • Community Member Profile Picture
    on at

    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.

  • Community Member Profile Picture
    on at

    I will try this workaround. Thank You !

  • Jonathan  Halland Profile Picture
    11,310 on at

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

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans