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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Finance forum / Accesing form variable...
Finance forum

Accesing form variables on pre or post event handler

(0) ShareShare
ReportReport
Posted on by 1,400

Hi guys. I was trying to extend the SalesEditLines form, but I ran into the following problem:

I have to extend the functionality of the reArrange method, but to do that, I need to access the current state of a class on the pre reArrange at the time of the call to the method, but because the pre event handler is static, I can't do that. I'll give an example:

[ExtensionOf(formStr(SalesEditLines))]
final class SalesEditLinesEventHandlers_Extension
{

public someClass someClassInstance = someClass::construct();

[PreHandlerFor(formStr(SalesEditLines), formMethodStr(SalesEditLines, reArrange))]
public static void SalesEditLines_Pre_reArrange(XppPrePostArgs args)
{

//in here I need to access someClassInstance current state

}

}

Is there any way to do that?

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    239,660 Most Valuable Professional on at

    If you mean the state of SalesEditLines, use args.getThis() to get a reference.

    If you mean the state of SalesEditLinesEventHandlers_Extension, use non-static event handlers.

  • greengrimms Profile Picture
    1,400 on at

    Hi Martin, thank you for answering.

    Yes, I'm aware of that, but in this particular case, I can only use a pre or a post event handler which, as far as I know, must be static.

    Do you think there's another way to achieve this?

  • Verified answer
    Martin Dráb Profile Picture
    239,660 Most Valuable Professional on at

    I wouldn't use pre-/post-method event handlers in the first place. I haven't created a single one since the introduction of Chain of Command (CoC).

    Why aren't you using CoC? It's easier to write and read and it your current problem doesn't exist there.

  • greengrimms Profile Picture
    1,400 on at

    Wait a minute... I thought we couldn't use CoC on forms, but I just tried it and it worked... Did they change that on a newer version or was I just wrong this whole time?

    Anyway, you just saved me a whole lot of trouble. Thank you so much Martin!

  • greengrimms Profile Picture
    1,400 on at

    I just read the documentation and it states very clearly that you can use CoC on forms, just not on its nested classes (eg. datasource and form control methods). I clearly misunderstood the documentation. Thanks for the help!

  • Community Member Profile Picture
    on at

    Hi Martin,

    Can you share your piece of code where you have successfully executed the CoC for forms so that I can have little clarity on this.

    I am also trying to execute the same in my scenario.

    Thanks.

  • Martin Dráb Profile Picture
    239,660 Most Valuable Professional on at

    It's trivial. Here is a simple example:

    [ExtensionOf(formStr(AForm))]
    final class AForm_Extension
    {
        public void run()
        {
            next run();
            info("Extended!");
        }
    }
  • Community Member Profile Picture
    on at

    Thanks for the prompt reply Martin.

    I tried this.

    [ExtensionOf(formdatafieldstr(FormName,DataSource, VendAccount))]

    final class className_Extension

    {

           public void modified()

           {

               info('Hi');

               next modified();

           }

    }

    But I am trying CoC for some methods like modified so getting error.

    Error 1:

    The first argument to the 'ExtensionOf' attribute must use the appropriate intrinsic function classstr, tablestr, dataentityviewstr, mapstr, viewstr, formstr or querystr.

    Error 2:

    The next method cannot be invoked in method 'modified' because it's not a Chain Of Command Method.

    Can not we use CoC in such cases ? or am I doing something wrong ? Kindly correct me.

    Therefore I asked if any document or referecne code is available for when to Use CoC or otherwise.

    Version Details :- Platform release Update12 (7.0.4709.41129)

    Thanks in advance.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Finance

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans