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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How to traverse the controls of Form extension?

(0) ShareShare
ReportReport
Posted on by 932

Hi,

I want to get the controls of formRun, I use this approch to get all controls of standard and extension form.

Then I want to get the path of each control.

It is possible to use this approch in D365 Fo?

Thanks.

I have the same question (0)
  • BASMA Profile Picture
    932 on at
    RE: How to traverse the controls of Form extension?

    Thanks a lot Martin :)

  • Suggested answer
    Martin Dráb Profile Picture
    236,142 Most Valuable Professional on at
    RE: How to traverse the controls of Form extension?

    I understand your confusion, but you must realize that the CLR enum Microsoft.Dynamics.AX.Metadata.Core.MetaModel.FormControlType and the X enum FormControlType are two different types and you can simply compare their values.

    To use the right type, you may use the fully qualified name:

    axFormControl.Type == Microsoft.Dynamics.AX.Metadata.Core.MetaModel.FormControlType::CommandButton

    but it's cumbersome, therefore it's better to utilize the using statement:

    using meta = Microsoft.Dynamics.AX.Metadata.Core; // this will be one the top of the file
    
    ...
    
    axFormControl.Type == MetaModel.FormControlType::CommandButton

    Nevertheless you may greatly benefit from working with class (and interface) types directly, which you can easily do with is and as operators.

    For example, what about replacing your complete code with just a single line?

    return axFormControls is IAxFormActionButtonControl;

  • BASMA Profile Picture
    932 on at
    RE: How to traverse the controls of Form extension?

    Thanks Martin for your help,

    I changed the title of post :)

    By the way, I want to get the type of "AXFormControl", I added this code:

    if((axFormControl.Type==FormControlType::MenuFunctionButton)||
      (axFormControl.Type==FormControlType::CommandButton) ||
      (axFormControl.Type==FormControlType::DropDialogButton) ||
      (axFormControl.Type==FormControlType::Button))
        return true;

    I got error : 
    "Error The enum types 'Microsoft.Dynamics.AX.Metadata.Core.MetaModel.FormControlType' and 'Enumeration(FormControlType)' are incompatible. "

  • Verified answer
    Martin Dráb Profile Picture
    236,142 Most Valuable Professional on at
    RE: How to traverse the controls of FormRun

    Name is a property, not a control. Also, the value is string, not a FormControl object.

    Look at how I would write the code:

    AxFormExtension formExtensions = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetFormExtension(myFormExtensionName);
    
    var enumerator = formExtensions.Controls.GetEnumerator();
    while (enumerator.MoveNext())
    {
        AxFormExtensionControl extControl = enumerator.Current;            
        str name = extControl.FormControl.Name;
    }

    By the way, notice that the title has a wrong name. It talks about FormRun class that we're not using at all. As I mentioned before, it's important to focus on requirements first and only later choosing particular implementation details.

  • BASMA Profile Picture
    932 on at
    RE: How to traverse the controls of FormRun

    I means that I want to get the value of every formExtensionControl, I use this code :

    AxFormExtension formExtensions = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetFormExtension(MyFormExtensionName);
                    var  axFormExtensionControl= formExtensions.Controls;
    
                    List=axFormExtensionControl.getEnumerator();
                    while(List.moveNext())
                    {
                        var controlExtension = List.get_current();
                        FormControl  formControl=controlExtension.FormControl.Name();
                      }

    But I get error : "Error The qualifier 'controlExtension' is not valid for field 'FormControl'. "

  • Martin Dráb Profile Picture
    236,142 Most Valuable Professional on at
    RE: How to traverse the controls of FormRun

    Sorry, it's not clear to me what problem you have. Please elaborate.

  • BASMA Profile Picture
    932 on at
    RE: How to traverse the controls of FormRun

    Thanks Martin,

    I use this and I get the number of controls:

     AxFormExtension formExtensions = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetFormExtension(tname);
         var  axFormExtensionControl= formExtensions.Controls;

    6472.control.png

    Now I want to get the name of this button in red, it is possible to do this?

  • Suggested answer
    Martin Dráb Profile Picture
    236,142 Most Valuable Professional on at
    RE: How to traverse the controls of FormRun

    You don't get any controls because you've created a new, empty object.

    The easiest way to get an AxFormExtension object for an existing form extension is using Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetFormExtension(MyFormExtensionName).

  • BASMA Profile Picture
    932 on at
    RE: How to traverse the controls of FormRun

    Hi @Martin Dráb,

    Can you help to find axFormExtension

    I use this code:

    var axFormExtension = new Microsoft.Dynamics.AX.Metadata.MetaModel.AxFormExtension();
    
    var tname =MyFormExtensionName;
    
    

    I want to get controls of "MyFormExtensionName" using 

     var axFormExtensionControl= axFormExtension.Controls;  => this instruction doesn't return any controls

  • Martin Dráb Profile Picture
    236,142 Most Valuable Professional on at
    RE: How to traverse the controls of FormRun

    No, you still didn't explain whether your business requirement requires getting controls at runtime or from form definition (metadata).

    We could have decided what's needed from technical perspective if you shared the business requirement.

    Unfortunately you didn't answer any of these points. So either you can decide it by yourself or you'll share enough information with us so we can decide it on behalf of you. There is no other way.

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 1,239

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 767 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 672 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans