Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Refresh a certain form from another form

Posted on by 315

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

  • Verified answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Refresh a certain form from another form

    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.

  • NewWatermelon Profile Picture
    NewWatermelon 315 on at
    RE: Refresh a certain form from another form
    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?

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Refresh a certain form from another form

    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
    NewWatermelon 315 on at
    RE: Refresh a certain form from another form

    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
    nmaenpaa 101,156 on at
    RE: Refresh a certain form from another form

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

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Refresh a certain form from another form

    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.

  • NewWatermelon Profile Picture
    NewWatermelon 315 on at
    RE: Refresh a certain form from another form

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

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Refresh a certain form from another form

    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.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans