How to write the COC methods of CustTable in D365

COC stands for Chain of Command, which is a design pattern that allows you to extend the logic of public and protected methods of a base class without using event handlers. You can use COC to add methods to tables through extension classes in D365FO.

To use COC for table methods, you need to follow these steps:

• Create a new class and name it <TableName>_Table_Extension, where <TableName> is the name of the table that you want to extend.

• Add the attribute [ExtensionOf(tableStr(<TableName>))] to the class definition, where tableStr is a global function that returns the name of the table as a string.

• Add the methods that you want to extend or override in the extension class, using the same signature as the base class methods. You can access public and protected methods and variables of the base class in your extension methods.

• Use the next keyword to call the base class method from your extension method, if you want to wrap around the existing logic. You can also skip calling the next method if you want to replace the logic completely.

Here is an example of how to use COC for table methods:


// This is the base class

class CustTable

{

    public void insert()

   {

       // Some logic

   }


   public void validateWrite()

   {

       // Some logic

   }

}


// This is the extension class

[ExtensionOf(tableStr(CustTable))]

final class CustTable_Table_Extension

{

   // This method wraps around the base class method

   public void insert()

   {

      // Some additional logic before calling the base method

      next insert(); // Calling the base method

      // Some additional logic after calling the base method

   }


   // This method overrides the base class method

   public void validateWrite()

   {

      // Some different logic, not calling the base method

   }

}

Comments

Popular posts from this blog

Build HTML and send email in D365 FO with X++

How to customize electronic reporting in D365

Batch parallelism or multithreading in Dynamics 365 for Finance and Operations

How to Enable/Disable a Form Button with X++

How to create and run the Runbase batch class in D365

How to create and run the Runbase class in D365

Difference between InMemory and TempDB tables in D365 F&O

Customize the standard excel template in D365FO

How to create and run a batch class that extends RunBaseBatch in D365

How to apply a package in LCS Dynamics 365 F&O