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)

Init Method Extension in Dynamics 365 ax7

(0) ShareShare
ReportReport
Posted on by

Hi friends,

             I am trying to call my extension method in post event handler, but i am getting error like

"ClassDoesNotContainMethod: Table 'LedgerJournalTable' does not contain a definition for method 'getDebitBalance' and no extension method 'getDebitBalance' accepting a first argument of type 'LedgerJournalTable' is found on any extension class".

My extension class is

public static class LedgerJournalTable_Extension1
{
public static real getCreditbalance(LedgerJournalTable _LedgerJournalTable)
{
LedgerJournalTable ledgerJour;


select * from ledgerJour
where ledgerJour.JournalNum == _LedgerJournalTable.JournalNum;

return ledgerJour.JournalTotalCredit;

             }

           }

and my post init method is like,

[PostHandlerFor(formStr(LedgerJournalTable), formMethodStr(LedgerJournalTable, init))]
public static void LedgerJournalTable_Post_init(XppPrePostArgs args)
{
LedgerJournalTable  ledgerJ;
LedgerJournalTable ledgerJournalTable = args.getThis() as LedgerJournalTable ;

ledgerJournalTable.getCreditbalance(ledgerJ);
}

Please suggest an solution for this error , how an call extension from method inside post init method .

Thanks & regards,

padmapriya

*This post is locked for comments

I have the same question (0)
  • Sohaib Cheema Profile Picture
    49,438 User Group Leader on at

    Sounds like models are not referred well. Please make sure your Suite is getting reference of those suites which are having these methods. it also happens sometimes that the method itself contains something which further refers to another suite. in such case that 3rd or 4th level of package also need to be referenced. this can be done by updating model parameters.

  • Community Member Profile Picture
    on at

    Hi Sohaib Cheema,

                        i created extension method in form method like,

    3771.d2.png

     

    and after that i tried to create post init method in extension of that form,

    3771.d2.png

     

     

    i refreshed the modules also , but i dont know where is the error.

     

  • Sohaib Cheema Profile Picture
    49,438 User Group Leader on at

    Thank you for posting these images. My suspicion is still as described previously.

    do you want to have a look at to which suite the method getCredit.. belongs?

    Also please note the Model/Suite for LedgerJournalTable.

    Then finally make sure if those suits that you have found above are referenced in your extension model.

  • Community Member Profile Picture
    on at

    Hi Sohaib,

                    The extension method call 'getcreditbalance' is created by me in same model. and i referenced all the model in my model name called  'customization'. But same issue is their.i refreshed my module also .

  • Sohaib Cheema Profile Picture
    49,438 User Group Leader on at

    how you have refreshed models? do you want to give a try to full rebuild?

  • Verified answer
    Shahil Profile Picture
    635 on at

    Hi Padma

    I'm not sure which platform you're on but if you're on the 7.1 then what I see is wrong.

    If you creating an extension of a class/table/form then you need to use ExtensionOf attribute and make it final instead of static so you are not confined to creating static methods only. And if you are creating a extension then your class name has to end with "Extension" rather than "Extension1" regardless of the platform you are on.

    Please refer to this on how to create an extension class: docs.microsoft.com/.../class-extensions

    From the screenshots that you have put up, I can see that you're creating a post handler of the form init method. Why not use the OnIntialized event? Nonetheless, your post-handler looks wrong as well. Your method is static, you won't be able to call it using a dot operator anyway.

    So a few pointer:

    1. If you're on 7.1 or above, this is how your extension class should look like:

    [ExtensionOf(tableStr(LedgerJournalTable))]
    public final class LedgerJournalTable_Extension

    2. Change your method from static to non-static and you don't need send in the record

    public real getCreditbalance() 
    { 
        LedgerJournalTable ledgerJour;
    
        select * from ledgerJour 
           where ledgerJour.JournalNum == this.JournalNum; 
    
        return ledgerJour.JournalTotalCredit; 
    }
    



    3. Post-handler:

     [PostHandlerFor(formStr(LedgerJournalTable), formMethodStr(LedgerJournalTable, init))]
        public static void LedgerJournalTable_Post_init(XppPrePostArgs args)
        {
            //args.getThis() will return you an instance of the formRun
            FormRun formRun = args.getThis();
            //From this you need get your LedgerJournalTable cursor
            LedgerJournalTable ledgerJournalTable = formRun.dataSource(formdatasourcestr(LedgerJournalTable, LedgerJournalTable)).cursor() as LedgerJournalTable;
            //call your method
            real creditBalance = ledgerJournalTable.getCreditbalance();
        }

    Try this out

    Let me know how it goes.

     
  • Community Member Profile Picture
    on at

    Hi Ram,

          I followed your code it works, thanks a lot man.

    Thanks & regards,

    padmapriya

  • Community Member Profile Picture
    on at

    Hi Sohaib,

                 Thanks for your reply, i refreshed the models and full build too .i got the solution by following ram response.thanks for our response too.

    Thanks & regards,

    padmapriya

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