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)

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

    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

  • Suggested answer
    Axaptus Profile Picture
    10 on at

    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;
        }
    
    }


  • Mea_ Profile Picture
    60,284 on at

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

  • Community Member Profile Picture
    on at

    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

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

  • Axaptus Profile Picture
    10 on at
    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.
  • Sarunas Gruodis Profile Picture
    60 on at

    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 ;
    }

  • Suggested answer
    Mea_ Profile Picture
    60,284 on at

    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

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
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans