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.

7 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
    Replies
    1. Yes you can use the next functionality and perform the action.

      Delete
  3. The information which you have provided in this blog is really useful to everyone. Thanks for sharing.
    MS Dynamics AX Online Training

    ReplyDelete
  4. Attractive, post. I just stumbled upon your weblog and wanted to say that I have liked browsing your blog posts. After all, I will surely subscribe to your feed, and I hope you will write again soon! 3PL warehouse service

    ReplyDelete
  5. This requires patching up our educational programs, revamping our course readings, retraining our educators, and understanding that we should do this ourselves. We do have a rich history of doing it. It is safe to say that we are at last able to go to our own in-house fortunes to re-try schooling the manner in which it ought to consistently have been? education

    ReplyDelete
  6. Thinking back, it's not difficult to distinguish why instruction was significant for me, and it's not difficult to clarify why it's significant for you. The critical inquiry to answer is: would you be able to perceive any reason why it's significant? Now and again that is troublesome, particularly when you're confronting it or going through it. Long stretches of instruction can appear to be a long period of exertion.pre school Singapore

    ReplyDelete

Powered by Blogger.