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)

Enable / Disable fields in a Form

(0) ShareShare
ReportReport
Posted on by 634

Hi Guys, 

I have created a form where i need to enable / Disable some fields based on some conditions. Can someone clarify the below.?

I have two fields in a table called TestTable

Field A( Checkbox  No/Yes), Field B (String). field B should be active for editing only if the Field A is selected

I set is as shown below,  In the Form i added a SetfieldAccess method 

public void setFieldAccess()
{

TestTable.object(fieldNum(TestTable, FieldB)).allowEdit(False);

if(TestTable.FieldA == NoYes:: Yes)

{

TestTable.object(fieldNum(TestTable, FieldB)).allowEdit(True);

}

TestTable_ds.refresh();

}

and in the active method of the data source 

public int active()
{
int ret;

element.setFieldAccess();

return ret;
}

1. My problem here is whenever I selected the checkbox I need to either refresh the form or click on the field B or anywhere in the form to enable the field B active. its not refreshing automatically. how can I do that ? 

2. Is above the proper way to set fields enable or disable in a form ?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    If you want to hide/show fields based on data you need to call your logic from two places:

    - Modified method / event of the field that should trigger the change.

    - Active method of the data source where the trigger field exists.

  • D365  beginner Profile Picture
    634 on at

    Thanks for the quick response Mr. Nikolaos,

    can you show me a sample code for the above in that case. I have added another validations also in the same form and that's why I need to know the proper way to do it without affecting other modifications.

  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    The following example is not an example of how your final solution should look like. It's just intended to demonstrate how you can react on the field value after the user has changed it, and when the active record of the data source changes.

    Let's assume that if user inputs "foo" in Table1.Field1, you want to hide Control1. And if there is any other value than "foo", Control1 will be enabled.

    1) Set Autodeclaration for Control1 to Yes

    2) This is how modified method for Field1 of your Table1 data source should look like:

    public void modified()
    {
        super();
        if (this.getValue() == 'foo')
        {
            Control1.visible(false);
        }
        else
        {
            Control1.visible(true);
        }
    }

    3) This is how active method of Table1 data source should look like:

    public int active()
    {
        int ret;
    
        ret = super();
    
        Control1.visible(Table1.Field1 == 'foo' ? false : true);
    
        return ret;
    }

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
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans