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)

Refresh a certain form from another form

(0) ShareShare
ReportReport
Posted on by 327

In a form Y close() event, I want to refresh a form X.

Form X is not the parent form of form Y.

How can I accomplish this?

Thanks in advance.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    You have to have some kind of link between these forms. Basically you have to be able to pass the FormRun instance of your form X to form Y. Otherwise you can't call the refresh.

  • NewWatermelon Profile Picture
    327 on at

    There is a class called by form X to call form Y.

  • Suggested answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    Then you should be able to enhance this class to include reference to the caller form. Maybe it already exists?

    For example if it's called through a menu item, the caller can be present in args.caller().

    Can you proceed with this info? If not, please provide your code.

  • Suggested answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    Please look into the product documentation, too: docs.microsoft.com/.../how-to-refresh-the-calling-form

  • NewWatermelon Profile Picture
    327 on at

    I got your idea and I already have this docs page. How can I fire my code with form Y close() event?

  • Suggested answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    There is a code sample for this exact case in the doc page. So that is how you fire it.

    If it's a standard form, you have to hook into the OnClosing event handler instead of using the closeOk method that is in the code sample. In the event you have FormRun of form Y in variable called sender.

    sender.caller() returns the caller. You have to have either form X as the caller, or have a method in the caller that gives you the FormRun of form X. Then you can call the refresh of the FormRun of form X.

    This is as much as I can help with your general level question. Since I know nothing about your forms and classes I can't give more specific help.

  • NewWatermelon Profile Picture
    327 on at
    Here is my Handler class main method:

    static void main(Args args) { MyHandlerClass handler; Table1 ParentTable; Table2 ChildTable1; Table3 ChildTable2; if (args && args.record()) { switch (args.menuItemName()) { case (menuitemactionstr(MenuItem1)): ParentTable = args.record(); handler = MyHandlerClass::construct(); handler.parmId(ParentTable.Id); handler.run(); break; } } }

    I open form Y with the following class method:

    void openForm()
    {
        FormRun formRun;
        Args args = new Args();
        ;
    
        args.name(formstr(FormY));
        args.record(ParentTable);
        formRun = ClassFactory.formRunClass(args);
        formRun.init();
        formRun.run();
        formRun.wait();
    }

    Now I want to refresh form X when form Y get closed.

    You already told me to do it within my class.

    How can I do it?

  • Verified answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    I assume the main method of the handler class is called from form X.

    1) add new variable FormRun formX in your handler class. And add method parmFormX for getting and setting that variable

    2) in your main method, add this line of code: handler.parmFormX(args.caller());

    3) in openForm method add this line of code: args.caller(this);

    Now in your form Y you can reach your handler class like this:

    MyHandlerClass handler = args.caller():

    And you can reach form x like this:

    FormRun formX = handler.parmFormX();

    Now you can call any methods of form X from form Y by using this formX variable.

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