Skip to main content

Notifications

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

  • Giridhar1617 Profile Picture
    Giridhar1617 on at
    RE: How add a method extension in an extension form

    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

  • Martin Dráb Profile Picture
    Martin Dráb 230,842 Most Valuable Professional on at
    RE: How add a method extension in an extension form

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How add a method extension in an extension form

    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

  • KevinGroves Profile Picture
    KevinGroves 30 on at
    RE: How add a method extension in an extension form

    Make the post_updateButton method none static and it should work.

  • Foxsor Profile Picture
    Foxsor 160 on at
    RE: How add a method extension in an extension form

    Thank Martin.

  • Martin Dráb Profile Picture
    Martin Dráb 230,842 Most Valuable Professional on at
    RE: How add a method extension in an extension form

    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
    Foxsor 160 on at
    RE: How add a method extension in an extension form

    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."

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,842 Most Valuable Professional on at
    RE: How add a method extension in an extension form

    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.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,969 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,842 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans