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)

how to set mandatory field control per line in form AX 2012

(0) ShareShare
ReportReport
Posted on by 10,280

plz somebody help me

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    239,660 Most Valuable Professional on at

    You weren't very generous in words, but I assume that you have a form control bound to a data source and you would like to sometimes show the field as mandatory, depending on values of some other fields in the same record.

    If my description is correct, try to write it by yourself next time.

    If it isn't, you see that you have to provide more details if you want to get an answer.

    Assuming that I understand what you want, the answer is that you can override the active() method of the data source and set the mandatory property to true of false for the active record based on any condition you like.

  • Codehunter Profile Picture
    10,280 on at

    I did using the below code in active() but no changes occur

    if(Ledgerjournaltable.category=="")

    control.mandatory(true);

  • dolee Profile Picture
    11,279 on at

    Hi Codehunter,

    I made a quick demo based on Martin's suggestion and I can verify that it works on my DEV machine.

    If you can't figure out what's wrong, consider posting some screenshots of your implementation here.

  • Sohaib Cheema Profile Picture
    49,668 Super User 2026 Season 1 on at

    if your control is bound to a datasource field (i.e. your control has a table field behind)

    you should not use the code as you are using. you should write code as under

    if(!LedgerJournalTrans.category)
        {
            LedgerJournalTrans_DS.object(fieldNum(LedgerJournalTrans,YourFieldName)).mandatory(true);
    }
    else
    {
    LedgerJournalTrans_DS.object(fieldNum(LedgerJournalTrans,YourFieldName)).mandatory(false);
    }


     Referring control directly [control.mandatory(true);] is not good because of following reason:

    • you have to refer field multiple times, if its being used in design multiple time.

    Referring to control is only suggested when control is not bound to Dataset. In that case AutoDecleration property of  control should be YES.

  • Codehunter Profile Picture
    10,280 on at

    I have to add that code in modified() method of the field or what?? And ledgerjournaltrans_ ds is that a buffer or what/?? Plz reply to me ASAP

  • Martin Dráb Profile Picture
    239,660 Most Valuable Professional on at

    modified() method of the field is executed when the user changes the value of the field. How would it help you to set the field as mandatory before user actually starts changing the value? It's no way to go.

    ledgerjournaltrans_ ds is an object representing a form data source. As always, you'll learn more about them in the documentation: Form Data Sources.

  • Sohaib Cheema Profile Picture
    49,668 Super User 2026 Season 1 on at

    you have to add code in active method of DataSource after super();

    Better would be if you put your code at end of standard AX code.

    ledgerjournaltrans_ds represents your datasource (see your previous reply you have it there)

  • Codehunter Profile Picture
    10,280 on at

    I added that code but nothing works ;it just keeps that field not mandatory in modified() of selected field

  • Sohaib Cheema Profile Picture
    49,668 Super User 2026 Season 1 on at

    Can you please show your code?

    and where you have written your code?

  • Codehunter Profile Picture
    10,280 on at

    the method is that the modified method of selected control

    Modified()

    {

    if(LedgerJournaltable.Category=="Subcontractors")

    {

    LedgerJournalTable_ds.object(fieldnum(LedgerJournaltable,Ledger_worderid)).mandatory(true);

    }

    else

    {

    LedgerJournalTable_ds.object(fieldnum(LedgerJournaltable,Ledger_worderid)).mandatory(false);

    }

    }

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 Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 21

#2
dekion Profile Picture

dekion 4

#2
Virginia99 Profile Picture

Virginia99 4

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans