D365 Finance and Operations-COC

 

There are many numbers of objects that exist on D365 FO that can use a chain of command (COC). So, I am listing some of them.

  1. Tables
  2. Classes
  3. Forms
  4. Form's Data sources
  5. Form's Data fields
  6. Form's Controls
  7. Data Entities

Rules of COC

  • All the COC classes must contain _Extension at the end of the name of the class.
  • COC class must contain the final keyword which denotes that the class cannot be further extended.
  • COC class must contain the attribute [ExtensionOf()]
  • Method definition will be defined exactly the same way as the base class contains.
  • That method must call the base class method with the next keyword.


[ExtensionOf(Classstr(SalesOrderDP))] 
final class SS_SalesOrderDP 
{ 
      // Method you want to Extend 

      Public void <MethodName>
      { 
        // Prefix Code next

           next <MethodName>;

        // Postfix Code 
                    
                    
       }
} 

NOTE: These rules will be applied for COC of any of the objects given above

COC of Table:

Suppose there is a custom field SS_Shipment (string) on salesTable and you need to apply validation on table level so when any transaction is performed this filled must be validated. First, I will follow the rules of COC which I mentioned above.


[ExtensionOf(tablestr(SalesTable))] 
final class SS_SalesTable_Extension
 { 
    public boolean validateWrite()
    { 
          Boolean ret = next validateWrite();

         // Additional Code 

          If(this.SS_Shipment == “”)
          { 
             ok = checkFailed(“SS_Shipment field is mandatory”);
          }

         return ret;
    } 
 }

COC of Class: 

Suppose there is a class called ClassA having methodA and you need to execute your code before or after the execution of MethodA.

[ExtensionOf(classstr(ClassA))] 
final class SS_ClassA_Extension
{ 
    public void methodA()
    { 
      // Additional Code before execution of base method
 
         next methodA(); 

     // Additional Code after execution of base method 
    }
 }
                                  
                                    

COC of Forms:

Suppose there you need to work on the init of the form then you will use this type of COC.

[ExtensionOf(Formstr(<FormName>))]
final class SS_SalesTable_Extension
{
  public void init()
  {

    // Customize code

       next init();
    
    // Customize code
          
  }
        
            
}
              
            
              

COC of Form’s Data Source:

Do you have any button that you need to enable/disable based on the record you have selected on the grid then you need to create COC of the active method of Form DataSource? 

[ExtensionOf(formdatasourcestr(<FormName>, <DataSourceName>))]
final class SS_SalesTable_Extension
{

   public int active()
   {

      // Additional Code before execution of base method
            
      int ret = next active();
             
      // Additional Code after execution of base method
            
      SalesLine _SalesLine = this.cursor();
      if(SalesLine.Status == NoYes::No)
      {
            
         this.formRun().design().ControlName(formControlStr(<FormName>,<ControlName>)).enable(false);
            
      }
      else
      {
            
         this.formRun().design().ControlName(formControlStr(<FormName>,<ControlName>)).enable(true);
            
            
       }
            
       return ret;
            
   }
            
}

COC of Form’s Data Field:

Suppose when you select ItemId on the form and on modification of itemId field you want the name of the item is automatically mapped to the desired field of yours then can use COC of FormDataField.

[ExtensionOf(formdatasourcefieldstr(SalesTable, SalesLine,ItemId))
final class SS_SalesTable_Extension
{

   public void modified()
   {

           

        // Additional Code before execution of base method

           next modified();
           
        // Additional Code after execution of base method

           FormDataObject _formDataObject= any2Object(this) as FormDataObject;
           FormDataSource _FormDataSource= formDataObject.dataSource();
           SalesLine _salesLine = FormDataSource.cursor();
           _salesLine.Name  = InventTable::Find(_salesLine::ItemId).ItemName();

 
   }

}

COC of Form’s Control:

Suppose there is a case where you need to check if Status is active or not while clicking on the button (Control) and based on this you are performing some actions then you need to use COC of FormControl.

[ExtensionOf(formControlstr(<FormName>,<ControlName>))
final class SS_ClassA_Extension
{

  public void Clicked()
  {

           

     // Additional Code before execution of base method

       next Clicked()  

     // Additional Code after execution of base method

       FormButtonControl _control = any2Object(this) as FormButtonControl;
       SalesTable _salesTable =   _control.formRun().dataSource(FormDataSourcestr(<FormName>,  <FormDataSource>)).cursor() as SalesTable;
         if(_SalesTable.Status == NoYes::No)
         {

            // Some Logic

         }
         else
         {

            // Some Logic

         }

   }

}

Comments