Showing posts with label Delegates. Show all posts
Showing posts with label Delegates. Show all posts

New Report or new Design of Existing Report in Print Management


New Report or new Design of Existing Report  in Print Management 


The simple way to add a new report or new design of an existing report in Print management 


Step-1 Create a new class SLD_DemoSample


Step-2 Find class PrintMgmtDocType in Application Explore and open in the designer 



Step-3 find the delegate in PrintMgmtDocType class  Delegate name is  getDefaultReportFormatDelegate



Step-4 Subscribe to the event of above-highlighted event in the newly created class


Step-5 Now add your report design in the EventHandlerResult _result


  /// <summary>
    ///
    /// </summary>
    /// <param name="_docType"></param>
    /// <param name="_result"></param>
    [SubscribesTo(classStr(PrintMgmtDocType), delegateStr(PrintMgmtDocType, getDefaultReportFormatDelegate))]
    public static void PrintMgmtDocType_getDefaultReportFormatDelegate(PrintMgmtDocumentType _docType, EventHandlerResult _result)
    {
        if(PrintMgmtDocumentType::CustInterestNote==_docType)
        {
            _result.result(ssrsReportStr(SLD_BinCart,Report));

        }
      
    }


Step-6 Perform build and sync and verify on D365FO

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








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.

Delegates to customize Application startup


                            Application Startup Event Manager 



In Dynamics AX 2012, there are some customization points that allowed us to subscribe to event Applications. Startup delegate those were raised when the client was initializing.

But in D365 those events were deprecated and introduce some new events were to customize the application startup as per your requirement.

You can find those events to subscribe to in-class  ApplicationStartupEventManager  



onSystemStartup()

  • This event occurs when the system starts up and Its raised once per AOS startup.

 onFirstTimeUserInteractiveSessionCreated()

  • This event occurs when the system is creating an interactive session for the first time for a user.

 onFirstTimeUserNonInteractiveSessionCreated()

  • This event occurs when the system is creating a non-interactive session for the first time for a user.

onInteractiveSessionCreated()

  • This event occurs when an interactive session is created and ready for use.
  • It is raised once per interactive session creation for any user.

onSessionCreated(boolean _isBatch, boolean _isInteractive)

  • This event occurs when the session is created and ready for use.
  • It is raised once per interactive session creation for any user.
  • _isBatch specifies whether the system is running a batch job.
  • _isInteractive specifies whether the session is interactive.


Let's begin to verify the above delegates

To verify the delegates we will log these events into a table.

Step-1 Create a class and subscribe to the delegate in this demo I have subscribed to only two delegates.

  • onSessionCreated
  • onSystemStartup




Step-2 Create a table and insert anything to verify that events are working or not.




Step-3 Stop the IIS and Batch services.
Step-4 Build & Sync model or project.
Step-5 Verify records on the newly created table using SQL.



Step-6 Restart The IIS services.  On this step systems, startup event will raise Once.

Step-7 Start Batch service. On these steps systems startup event will raise 14 times.  You can check the number of records of SQL is 15


Step-8 Login On D365.  On this step session created event will raise.
Step-9 Verify records on newly created Table using SQL.


Please let me know if you are facing any issues during the implementation of this blog 



 

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