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 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 ?
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.
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 ?
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.
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
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).
[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
Can you show us your code, please?
By the way, I moved your thread from Dynamics AX Forum to Dynamics 365 Finance Forum.
André Arnaud de Cal...
292,187
Super User 2025 Season 1
Martin Dráb
230,966
Most Valuable Professional
nmaenpaa
101,156