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


Custom Web Service in few steps D365FO

Custom Web Service in few steps D365FO


In this article, I will explain how we can create a basic custom Web Service in D365FO with few steps.



Step-1 Create a class with the name of IntegrationService and write a method get foo.

Reference screenshot

public class IntegrationService  
{
    public str getFoo()
    {
        return "Hello World";
    }
}

Step-2  Create Add new Service and associate your class with newly created service
Reference screenshot



Step-3 Class association with service.
Reference screenshot



Step-4 Add the method of your class in the service operations node that you want to expose.
 Reference screenshot



Step-5 Add a Service group and associate your service with the service group.

Step-6 Set the service property Auto deploy= YES

Reference screenshot





Step-7 Perform Build & Sync and verify from browser.
Reference screenshot


Service URL 
https://usnconeboxax1aos.cloud.onebox.dynamics.com/api/services/[ServiceGroupName]/[ServiceName]/[MethodName]

Sample
https://usnconeboxax1aos.cloud.onebox.dynamics.com/api/services/IntegrationGroup/IntegrationService/getfoo


Follow this link to consume web service using POSTMAN

Support Faryal's Cusine


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...