UPDATE: 31/10/2017
Microsoft reached out and I have to correct my example code. It seems the compiler does not catch it when it is 2 nested conditions. See below code.
Be careful when using Chain of Command not to place the next() call in a condition.
Here is an example.
Create a class extension for a form. Call the method init() but place it in an “if” condition. Something like this.
[ExtensionOf(formStr(PurchReqCreate))]
final class PurchReqCreate_EAM_Extension
{
public void init()
{
info("Outer - Before next");
if (this.args() &&
this.args().record() &&
this.args().record().TableId == -100) //intentionally made it -100 to not execute this code
{
//doing something here
info("Inner - Before next");
if (this.args().record().TableId == -100)
{
info("Inside second if condition");
}
next init();
info("Inner - After next");
}
info("Outer - After next");
}
}
The compiler will not error or give you a warning. However, at run time you will get a misleading error.
In my case I got this. “Error executing code: Wrong argument type for function.”
Having a look at Event viewer (Folder: AX-XppRuntime), it gave me a little more info. At least I know the class that was calling it. I searched for any customization.
I found an extension class PurchReqCreate_Extension. I was able to eye ball and figure out the problem. Taking next() outside the “if” condition.
Rewrote the same:
public void init()
{
if (this.args() && this.args().record())
{
//do something before
}
next init();
if (this.args() && this.args().record()){
//do something after
}
}