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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How add a method extension in an extension form

(0) ShareShare
ReportReport
Posted on by 160
Hello,
I would like to create an extension form method on an extension form (ProjStatistic.Extension) in the form's methods in order to use it on a standard method  updateButton with a PostHandlerFor.
Is it possible to do this?, or the the syntax does not exist for creating an extension method in form?

/// <summary>
///  PostHandlerFor method of updateButton
/// </summary>
/// <param name="args"></param>
[PostHandlerFor(formStr(ProjStatistic), formMethodStr(ProjStatistic, updateButton))]
public static void ProjStatistic_Post_updateButton(XppPrePostArgs args)
{

// element.MySpecificExtensionMethod // How use an form extension method from the extension form?

}

*This post is locked for comments

  • Verified answer
    Martin Dráb Profile Picture
    241,656 Most Valuable Professional on at

    To seemingly add new methods, use class extensions. Yes, it works with forms as well, you'll just use [ExtensionOf(formStr(ProjStatistic))]. You can see an example in Code behind extension forms: How to add state variables and override methods without overlayering.

  • Foxsor Profile Picture
    160 on at

    Thank Martin.

    I could not use variables in form extension:

    [ExtensionOf( formstr( ProjStatistic )) ]

    final class ProjStatistic_Extension

    {

       public real xxxCalc;

       public static void xxxlCalc)

       {

          xxxCalc = 10;

       }

       /// <summary>

       ///

       /// </summary>

       /// <param name="args"></param>

       [PostHandlerFor(formStr(ProjStatistic), formMethodStr(ProjStatistic, updateButton))]

       public static void ProjStatistic_Post_updateButton(XppPrePostArgs args)

       {

       }

    I think my AX version (Platform1) did not support variables in form extension:

    "Fields on an extension class is only supported if the ExtensionOf attribute is used on a class."

  • Martin Dráb Profile Picture
    241,656 Most Valuable Professional on at

    It's possible; I don't gave the one-year-old version to test it.

    Note that the support for Platform Update 1 ends in less than three weeks, so you should upgrade very soon anyway.

  • Foxsor Profile Picture
    160 on at

    Thank Martin.

  • KevinGroves Profile Picture
    30 on at

    Make the post_updateButton method none static and it should work.

  • Community Member Profile Picture
    on at

    Hi Foxsor, Can you resolve the problem? I have a similar problem, but I can not solve it, in case you could share your solution, I would appreciate it, Regards

  • Martin Dráb Profile Picture
    241,656 Most Valuable Professional on at

    You should rather create a new thread and explain your specific problem.

  • Giridhar1617 Profile Picture
    on at

    Hi Martin,

    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 formRun object. Is it possible? When I try this, it says method does not exist on the form, actually it is existed on the underlying class extension. Can you please help me out how to solve this scenario?

    Regards,

    Giridhar

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
nmaenpaa Profile Picture

nmaenpaa 2 Moderator

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans