Friday 12 October 2018

Delegates in D365FO

Today, I will be discussing about how to use delegates in D365 finance and operations.  Delegate method are quite helpful in solving dependencies whenever we are trying to communicate between objects that exist in different models or packages. As per new structure of D365 we won't be able to use element outside the package or to whom we don't refer. But delegate functionality is something which will allow us to access elements in higher model from lower model. For instance we have a scenario in which model-A wants to call model-B object but it does not have reference of it. So in this case we will be using delegate. Delegation declaration must contain 3 things - Delegate keyword, void return type and method should be empty.

Lets say we want to modify a method by inserting code in the middle of it. Or we have a object which requires accessibility in higher model and on basis of that field we need to start or stop a validation. For the creation of delegate and subscribing to it following steps are required.

Step 1) Create a delegate method.





















Step 2) Create a Subscriber  to your delegate. For this go to your delegate method and right click on it. Select copy event handler class and paste it in your event handler class. Add your logic in the subscribed method.











Step 3) Invoke the delegate method in middle of class method where it is required.





















No comments:

Post a Comment

Note: only a member of this blog may post a comment.

Custom Business events Part 3 - (Activate custom business event) in D365 F&O

 In this blog we will discuss about the steps to activate a custom business in D365 F&O. As we know that business event catalog does not...