Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 369
AinsleyJ Avatar asked Mar 09 '23 03:03

AinsleyJ


2 Answers

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

like image 51
Matej Avatar answered May 14 '23 12:05

Matej


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
        }
    }
}
like image 31
Sumit Avatar answered May 14 '23 11:05

Sumit