Chain Of Command (method wrapping) in D365FO results in 'Object is not set to an instance of an object'

5.1k views Asked by At

I am trying to use the new 'Chain Of Command' feature in D365FO by extending CustTable.

We need to check if a value has changed on the update method, before we log it in a new table.

[ExtensionOf(tableStr(CustTable))]
final class CustTable_Extension
{
    void update(boolean _updateSmmBusRelTable = true, boolean _updateParty = 
                true)
    {
        CustTable   custTable_Orig = this.orig();
        boolean hasChanged = this.CreditMax != custTable_Orig.CreditMax;

        next update(_updateSmmBusRelTable, _updateParty);

        if(hasChanged)
        {
            //do something
        }
    }
}

However when running this code we get "Object is not set to an instance of an object" error. The error occurs because 'this' object is null. I also get the same error when calling "next update(_updateSmmBusRelTable, _updateParty);".

The documentation states: "This allows extending the logic of public and protected methods without the need to use event handlers. When you wrap a method, you can also access other public and protected methods and variables of the class."

Any ideas?

3

There are 3 answers

2
Matej On

You have to (re-)compile package with CustTable - Application Suite with PU9 or newer.

See https://learn.microsoft.com/en-us/dynamics365/unified-operations/dev-itpro/get-started/whats-new-platform-update-9#supported-versions:

However, this functionality requires the class being augmented to be compiled on Platform update 9. Because the current releases of the Dynamics 365 for Finance and Operations, Enterprise editon applications have been compiled on Platform update 8 or earlier, you will need to recompile a base package (like Application Suite) on Platform update 9 or newer in order to wrap a method that is defined in that package

0
ztirom On

I know that a long time passed on since the question was ask, but this one was a bug in Platform Updates lower than 13. This error fired in cases where a Form and a Table with the same name existed.

It was fixed with PU13.

0
Sumit On

Try removing default parameters value from your wrapper method.

[ExtensionOf(tableStr(CustTable))]
final class CustTable_Extension
{
    void update(boolean _updateSmmBusRelTable , boolean _updateParty )
    {
        CustTable   custTable_Orig = this.orig();
        boolean hasChanged = this.CreditMax != custTable_Orig.CreditMax;

        next update(_updateSmmBusRelTable, _updateParty);

        if(hasChanged)
        {
            //do something
        }
    }
}