Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

How do I retrieve information from a form's method in a class?

Posted on by 102

Hey! I need to modify the form for canceling a sales order so that when a user wants to cancel an order, he should mention a reason. The value selected from the field must then be saved in a field in the header of the SalesTable form. I called the main method of my dialog class on the clicked method and in run I called the closeOk method on the order cancellation form (SalesCancelOrderDropDialog). How do I retrieve the RecId for SalesTable in the run method to be able to put a value in my field? Or should I modify the closeOk method on the form? Thanks!

pastedimage1676271240867v1.png

pastedimage1676271277865v2.png

pastedimage1676271330237v3.png

pastedimage1676271529474v4.png

  • Pavel Ioana Profile Picture
    Pavel Ioana 102 on at
    RE: How do I retrieve information from a form's method in a class?

    Thanks, it worked for me!

  • Verified answer
    Janos Kovacs Profile Picture
    Janos Kovacs 130 on at
    RE: How do I retrieve information from a form's method in a class?

    Hi there! I would like to direct your attention to this article on creating good classes in Microsoft Dynamics AX: www.artofcreation.be/.../. This article provides valuable information and tips on how to create effective classes within Dynamics AX. You may also find the following code useful, although it is not the best solution as it shows some chaos in its structure.

    Here is the code:

    static void Job2(Args _args)
    {  
        FormRun         formRun;
        FormDataSource  formDataSource;
        SalesTable      salesTable;
        ;
        
        if (_args && _args.caller())
        {
            formRun = _args.caller();
            formDataSource = formRun.dataSource();
    
            if (formDataSource.table() == tableNum(SalesTable))
            {
                salesTable = formDataSource.cursor();
                
                if (salesTable.validateWrite())
                {             
                    salesTable.update();   
                }
            }
        }
    }


    I hope this helps you resolve your issue.

  • Martin Dráb Profile Picture
    Martin Dráb 230,198 Most Valuable Professional on at
    RE: How do I retrieve information from a form's method in a class?

    I don't think that click() method is the right place - use closeOk() instead.

    There is no SalesCancelOrderDropDialog in F&O (and I don't have any AX 2012 environment), therefore I can't look at the implementation. But you can. The form surely know which order it is about - maybe there is an instance variable, a data souce or a reference to a table holding the data. The debugger may help you to locate the information. When you know where to get it, then you can easily pass it to your class.

  • Suggested answer
    GirishS Profile Picture
    GirishS 27,832 Super User 2024 Season 1 on at
    RE: How do I retrieve information from a form's method in a class?

    Hi Pavel,

    On the main method you will get the caller record. Seems you already passed the args to parmArgs method from main method.

    On the run method you can get the SalesTable recid using parmArgs method like below.

    Public void run()
    {
        SalesTable salesTable = this.parmArgs().record();
    }

    Thanks,

    Girish S.

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans