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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Override protected new() method in class extension

(0) ShareShare
ReportReport
Posted on by 163

I made a class extension and I want to override new() method in class extension but when I do it I get an error (An extension class can only have a parameterless constructor.) so How Can I access this ?

I have the same question (0)
  • Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at

    Can you show us your code, please?

    By the way, I moved your thread from Dynamics AX Forum to Dynamics 365 Finance Forum.

  • Menna Allah Ahmed Profile Picture
    163 on at

    [ExtensionOf(classStr(InventJournalTableJumpRefHelper))]

    public final class InventJournalTableJumpRefHelper_Extension

    {

      public InventJournalTable inventJournal;

       public void jumpRef()

       {

       if (!inventJournal)

           {

               throw error(Error::missingRecord(tableId2PName(tableNum(InventJournalTable))));

           }

           next jumpRef();

           var jumpArgs = new Args();

           jumpArgs.record(inventJournal);

         var menuItemName = this.getMenuItem(inventJournal);

           var menuFunction = new MenuFunction(menuitemdisplaystr(InventJournalTableProjectCFM), MenuItemType::Display);

           menuFunction.run();

       }

      // // //<summary>

      // // //Opens the target form when the user clicks on journal ID.

      // // //</summary>

      // // //<param name = "_args">Lookup arguments.</param>

       public static void main(Args _args)

       {

           next main(_args);

           if (!InventJournalTableJumpRefHelper::isArgsValid(_args))

           {

               throw error(Error::wrongUseOfFunction(funcName()));

           }

           InventJournalTable journal = InventJournalTableJumpRefHelper::getJournalFromArgs(_args);

           var helper = InventJournalTableJumpRefHelper::construct(journal);

           helper.jumpRef();

       }

      // // //<summary>

      // // //Checks if the lookup arguments are valid.

      // // //</summary>

      // // //<param name = "_args">Lookup arguments.</param>

      // // //<returns>true if the lookup arguments are valid; otherwise, false.</returns>

       protected static boolean isArgsValid(Args _args)

       {

           boolean valid = next isArgsValid(_args);

           return true;

       }

      //  //<summary>

      //  //Checks if the lookup arguments are valid.

      //  //</summary>

      //  //<param name = "_args">Lookup arguments.</param>

      //  //<returns>true if the lookup arguments are valid; otherwise, false.</returns>

       protected static boolean isArgsValidCFM(Args _args)

       {

           return _args.record().TableId == tableNum(WMSJournalTable)

                   || _args.record().TableId == tableNum(PurchLine)

                   || (_args.lookupTable() == tableNum(InventJournalTable)

                   && _args.lookupField() == fieldNum(InventJournalTable, JournalId));

       }

       public str getMenuItem(InventJournalTable _inventJournal)

       {

           str result ;

           var journalStatic = JournalStatic::newTable(_inventJournal);

           if (_inventJournal.JournalType == InventJournalType::project)

           {

               result = menuItemDisplayStr(InventJournalTableProjectCFM);

           }

           else

           {

               result = journalStatic.menuItemStrLines();

           }

           if (result == '')

           {

               throw error(Error::wrongUseOfFunction(funcName()));

           }

           return result;

       }

    }

    this is my code so I want to override new() to make inventJournal has all values that returns in main mthod

  • Suggested answer
    Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at

    I meant the code cause the error. Anyway, let me comment on it in general...

    new() isn't a method. It's a constructor and constructors can't be extended. You can create a constructor for an extension, but it can't have parameters. It seems that you tried to use parameters. You can learn more about in F&O documentation: Class extension - Method wrapping and Chain of Command.

    In your case, the right approach maybe extending construct() instead of new().

    By the way, your code has double line spacing because you pasted it in a wrong way. Always use Insert > Code (in the rich formatting view).

  • Menna Allah Ahmed Profile Picture
    163 on at

    I tried to add new () without parameters but I got an errors

    How Can I override constract() and make it add values in my table buffer in extension (inventJournal) not table buffer in base class

    Screenshot-_2800_71_2900_.png

  • Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at

    As you see, you can't call the constructor from your model, because it's internal, and you would gave to provide the right parameters if calling it was possible. Let me remind you the code you shared before:

    InventJournalTable journal = InventJournalTableJumpRefHelper::getJournalFromArgs(_args);
    var helper = InventJournalTableJumpRefHelper::construct(journal);

    Nevertheless if your goal is just overriding construct(), you likely should do just that and you don't need to call it again from your code.

  • Menna Allah Ahmed Profile Picture
    163 on at

    Now It works well , I add a new method take Journal from main method and pass it to my table buffer .

    but now 2 forms opened old and new How can I fix this ?

  • Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at

    You indeed seem to calling the whole logic once more, despite the fact that it's not what you original asked for. And now you seem to be confirming that this new design of yours is wrong.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 669 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 471 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 423 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans