CHAIN OF COMMAND/COC ON A TABLE METHOD IN D365

 

When we want to change in the standard methods, and it cannot be easily achievable through the Extension or even through the event handler approaches then in that case we use the chain of command i.e., COC technique.

New form:

First, create a new form

add a new DataSource to the form with the following properties, selecting CustTable because we want to manipulate its name and address methods.
select simple list pattern for the form design and add different controls according to the pattern
by right-clicking on design and selecting new  and then add all these controls


Now add different fields that you want to manipulate, we added three different fields: Customer Name, Account and Address in the grid with the following properties.

 

Strings

Data Source

Data Method

Data Field

AccountNum

CustTable

 

AccountNum

CustomerName

CustTable

name

 

CustomerAddress

CustTable

address

 

 

 We choose DataMethod as the CustTable does not contain these particular fields. 

COC class:

Now add a new class with the suffix _Extension and tell in the first line that it is the extension of which table. And the class should be Final.


[ExtensionOf(tablestr(TableToExtend))]

Now add your logic the keyword next is very significant here as the execution of the code depends on the position of the code i.e., code is written pre- or post-the next keyword.

Code:

[ExtensionOf(tablestr(CustTable))]
final class RM_CustTable_Extension
{
    display CustName name()
    {
        str CustomerName;
        CustomerName = next name();
      //name() method return customer name from the original method  
        CustomerName = 'Guru Group_' + CustomerName;
        return CustomerName;
    }
 
    display logisticsaddressing address()
    {
        str custAddress;  
        custAddress next Address();
  //address() method return customer address  from the original method  
        custAddress = 'Guru Group_' + custAddress;
        return custAddress;
    }
       

Set form as the startup object and run the project.




 












Comments

Popular posts from this blog

Batch jobs stuck on WAITING status in AX 2012

Electronic Reporting For Beginners

Computed column and virtual field in D365