Skip to main content

Notifications

Announcements

No record found.

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

Best practice error - calling methods on forms

Posted on by 995

Hi,

Can somebody help me in fixing the below BP error when calling the custom method in in a form eventhandler.

In source system (AX 2012) it is possible to dynamically call methods where the number and type of the parameters does not match with the method definition. This is not supported in AX 7, where the number and types of parameters have to match. Even if the parameters do match, the late bound call is extremely expensive. Mitigation: Use a class or interface hierarchy to provide a type safe fast call, or use the IS and AS operators to cast to a known type before calling.

Below is the code that I am using.

4300.JPG

Kindly help me

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: Best practice error

    One option is moving the business logic from the form to a class. Then you can simply call methods by name and you don't need the hack with late-binding.

    If you're unable to refactor your code and the form is yours, you can let it implement an interface and call methods through this interface.

  • AX Techie Profile Picture
    AX Techie 995 on at
    RE: Best practice error

    Hi all,

    Still my question is unanswered. Can you please help.

    Thanks.

  • AX Techie Profile Picture
    AX Techie 995 on at
    RE: Best practice error

       public void hsoGetJournalData()

       {

           LedgerJournalTable  ledgerJournalTable;

           LedgerJournalName   ledgerJournalName;

           FormRun             element  = this;

           if (element.args().dataset() == tableNum(LedgerJournalTable))

           {

               ledgerJournalTable  = element.args().record();

               ledgerJournalName   = LedgerJournalName::find(ledgerJournalTable.JournalName);

               this.parmHSOIsRevenueReceiptJournal(ledgerJournalName.HSOIsRevenueReceiptJournal);

               this.parmHSOJournalNum(ledgerJournalTable.JournalNum);

               this.parmHSOIsJournalPosted(ledgerJournalTable.Posted);

           }

       }

  • Blue Wang Profile Picture
    Blue Wang on at
    RE: Best practice error

    Hi Avinash,

    Could you share your custom method code?

  • AX Techie Profile Picture
    AX Techie 995 on at
    RE: Best practice error

    Hi Blue,

    Yes I used. But getting this error  when I call that method.

  • Blue Wang Profile Picture
    Blue Wang on at
    RE: Best practice error

    Hi Avinash,

    Have you tried setting optional parameters in your custom method so that you don't need to match the number of parameters when you call it.

    docs.microsoft.com/.../using-optional-parameters

    Optional parameters also apply to AX7.

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

Product updates

Dynamics 365 release plans