Delegate Result with EventHandlerResult


Delegate Result with EventHandlerResult 


In this article, we will show to get Results from delegate subscribe events.


In normal routine mostly Ax Technical use subscribe event of delegates and perform the required task and get the required result. Following are the few steps through them you can achieve the same.

Let's begin.

Step-1 Create a class with the name of SLD_DemoSample
Step-2 Add two methods Main and run in this class like below screenshot

Reference screenshot

Step-3 Create a delegate in the class with two parameters like below

delegate void showMessage(Description _msg, EventHandlerResult result)  {    }

Reference screenshot

Step-4 Subscribe to the event of newly created delegate and paste to the class 

Reference screenshot


  /// <summary>
    ///
    /// </summary>
    /// <param name="_msg"></param>
    /// <param name="result"></param>
    [SubscribesTo(classStr(SLD_DemoSample), delegateStr(SLD_DemoSample, showMessage))]
    public static void SLD_DemoSample_showMessage(Description _msg, EventHandlerResult result)
    {
        result.result(strFmt("Message received from run method is %1",_msg));
    }

Step-5 Use result object of  EventHandlerResult class (2nd parameter) to return the response to caller like result.result(strFmt("Message received from run method is %1",_msg));

Reference screenshot



Step-6 Now call the delegate from the method and pass the required parameter like below.

        EventHandlerResult result = new EventHandlerResult();
        Description message='Hello world this is an event handler';
         
         info('Before..');

         this.showMessage(Message,result);
        
         info(result.result());

         info('After...');

Reference screenshot



Please feel free to contact me if you are facing any issues during the implementation of this blog.

Support Faryal's Cusine


No comments:

Post a Comment

Virtual Fields Vs Computed Fields

  Virtual Field: A virtual field in D365FO is a field that doesn't have a direct representation in the database. It's a field that y...