AX7: Chain of command: “Reference is not set to an instance of an object”

Have you ever tried to extend an object with the Chain of Command feature introduced with PU 9 and got the “Reference is not set to an instance of an object.” error?

TLDR: It’s a bug that is addressed in PU 13. The cause is that there exists a form that is named as your object which you try to extend with chain of command.

Test setup

To reproduce the error I simply created an extension class for the PurchTable table. I extended the initValue method by just adding an info call, where I wanted to get the PurchId form this.

The error

When you now go on and try to create a new purchase order you will get the following error:

AX Chain of Command Reference not set to an Object Application

If you attached the debugger, you will see where it throws the extension.

AX Chain of Command Reference not set to an Object Code

As you can see in the call stack, this is indeed null.

AX Chain of Command Reference not set to an Object This Null

Cause of the reference error

First of all there is not necessarily something wrong with your code. If you hit the link from the intro of this article, you will see the following post in the comment section:

AX7 Chain of command Reference not set to an instance of an object
So the “Reference is not set to an instance of an object.” error is always thrown when we try to make use of chain of command, where a form exists with the same name as the table you want to extend and you’re on an older version than PU 13.

In our example we used the PurchTable table and there also exists a PurchTable form. The test setup is also < PU 13.

As a workaround you can try to make use of a pre or post event handler and add your extension on that way.

Advertisement

You may also like...