Skip to main content

Dynamics 365 for Operations: Class extensions and Chain of Command (COC)-Next keyword

The functionality of extension classes (also known as class augmentation) is being improved to allow developers to wrap logic around methods defined in a base class. 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. This way, you can start transactions and easily manage state variables associated with your class.
Class Student
{
    real studentAge(int arg)
   {
    …
    }
}
It is now possible to extend the functionality of method1 using an extension class by reusing the same name to add pre-and post-logic to it.
[ExtensionOf(ClassStr(Student))]
class Student_Extension
{
    real studentAge (int arg)
    {
     var s = next studentAge(arg + 4);
    
      return s;
    }
}

Wrapping studentAge and the required use of the next keyword creates a Chain of Command (CoC) for the method. Here is what happens when the following code executes.
Student c = new Student ();
Print c. studentAge (33);

The system will find any method that wraps studentAge. It will randomly execute one of these methods (say, studentAge of the Student _Extension class). When the call to next studentAge() occurs the system will randomly pick another method in the CoC or call the original implementation if none exist.

Comments

  1. Bit confused to understand when said, system will randomly pick another method in the CoC...
    What exactly does it mean? Will it pick the method per hierarchy of class methods defined and then execute it accordingly like when a super call is encountered or what is the difference here?

    ReplyDelete
  2. Hi vishal,

    Thank you very much. This is very helpful. I have one small doubt, can we use this next keyword for table methods also?

    For example, i would like to modify some standard method from table. I will create an extension class for the table and can i use this next word to perform my additional functionality.

    Regards,
    Giridhar

    ReplyDelete

Post a Comment