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 :
Microsoft Dynamics AX (Archived)

Using "formHasMethod" validation for methods in class extensions of form.

(0) ShareShare
ReportReport
Posted on by

Hi ,

I have added a new method in the form using class extension. In the place where I am calling it, I would like to have a check if the "formHasMethod" and call the method using the formRun object. Is it possible? When I try this, it says method does not exist on the form, actually it exists on the underlying class extension. Can you please help me out how to solve this scenario?

Regards,

Giridhar

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mea_ Profile Picture
    60,284 on at
    RE: Using "formHasMethod" validation for methods in class extensions of form.

    Hi Šarūnas G,

    That's actually interesting one. Under the hood you will have 2 methods with different signature in case of optional parameters and methodInfo throws ambiguousMatchException because of that. I changed code a bit, so it should handle this as well github.com/.../Global_Extension.xml

  • Sarunas Gruodis Profile Picture
    60 on at
    RE: Using "formHasMethod" validation for methods in class extensions of form.

    such methods which used in x++ style like getters setters all in one wont work:

    public boolean parmBringBeer(boolean _bringBeer = bringBeer)
    {
          bringBeer = _bringBeer;

          return bringBeer ;
    }

  • Axaptus Profile Picture
    10 on at
    RE: Using "formHasMethod" validation for methods in class extensions of form.
    I forget to say at the moment. Thanks Ievgen for mentioning me in your post but I'm sure it is you who deserves all the credit!

    By the way, please try the better approach posted by Ievgen in his personal blog.
  • Mea_ Profile Picture
    60,284 on at
    RE: Using "formHasMethod" validation for methods in class extensions of form.

    It would be helpful, if you tell us more about parm method you created.

  • Community Member Profile Picture
    on at
    RE: Using "formHasMethod" validation for methods in class extensions of form.

    this won't work when checking if a parm method exists. You will get an ambiguous declaration exception.

  • Mea_ Profile Picture
    60,284 on at
    RE: Using "formHasMethod" validation for methods in class extensions of form.

    I would probably go further and use CoC to extend standard method.

  • Suggested answer
    Axaptus Profile Picture
    10 on at
    RE: Using "formHasMethod" validation for methods in class extensions of form.

    Hi!

    Following the ievgen's suggestion, you can create an extension like this:

    [ExtensionOf(classStr(SysFormRun))]
    static class SysFormRun__Extension
    {
        public static boolean hasMethodExtension(FormRun fr, IdentifierName methodName)
        {
            boolean ret;
    
            System.Type                     formRunType = fr.GetType();
            System.Type                     formRunExtensionType;
            System.Reflection.MethodInfo    mi;
            int i;
      
    
            System.Object[] extensions = Microsoft.Dynamics.Ax.Xpp.ExtensionClassSupport::GetExtensionsOnType(formRunType, true);
    
                if(extensions)
                {
                    for(i=0; i < extensions.Length; i++)
                    {
                        formRunExtensionType = extensions.GetValue(i);
    
                        mi = formRunExtensionType.GetMethod(methodName);
    
                        if(mi)
                        {
                            ret = true;
                            break;
                        }
                    }
                }
    
            return ret;
        }
    
    }


  • Suggested answer
    Mea_ Profile Picture
    60,284 on at
    RE: Using "formHasMethod" validation for methods in class extensions of form.

    Hi Giridhar1617,

    formHasMethod won't see method from extension class, so you need to add your own check  using new metadata API community.dynamics.com/.../new-metadata-api

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…

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Syed Haris Shah Profile Picture

Syed Haris Shah 9

#2
Mea_ Profile Picture

Mea_ 4

#3
KP-31070522-0 Profile Picture

KP-31070522-0 3

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans