Skip to main content

Notifications

Announcements

No record found.

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

  • Suggested answer
    Mea_ Profile Picture
    Mea_ 60,278 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
    Sarunas Gruodis 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
    Axaptus 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
    Mea_ 60,278 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
    Community Member Microsoft Employee 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
    Mea_ 60,278 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
    Axaptus 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
    Mea_ 60,278 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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,642 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,371 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans