Tuesday, October 29, 2019

Post Event Handler


In Dynamics 365 F&O we are not allowed to add our custom logic in between the core logic but we can execute our custom logic before and after the core logic and this can be achieved by using the Event handlers.
Microsoft® recommends usage of event handlers in every possible place because it is the best and safest way to customize any existing functionality to accommodate user requirements.

The are two types of Event Handlers

Pre-Event Handler    (Executed before the core logic)

Post-Event Handler   (Executed after the core logic)
Click here for more details about event handlers.

In this blog i will show you how can we create a Post-Event handler step by step.
Examples of Post-Event Handler:
Let’s take an example of table "LedgerJournalTrans" it has a method of "Insert" and we just need to inform the user after the record is "Insert" so we use the post event handler which inform the user about the inserted "Credit amount".

So here we can use the Post Event Handler.

You can use the Post-Event Handler for following purposes
1) Update Values
2) Warnings etc..


please follow the following steps


  1. Add a new class in your project and give it a proper name as "LedgerJournalTrans_Handler" or "LedgerJournalTrans_EventHandler"


  2.  Search the "LedgerJournalTrans" in the Tables node of Application Explorer and right click on the table then click on "Open designer"


  3. Open the "Methods" node of table then find the "Insert" and right click on the method then go to "Copy event handler method" then click on "Post-event handler"



  4.  Now come to the class "LedgerJournalTrans_Handler" and "Paste" then your class look like as shown below



  5. Now add the following code in your method and your final class look like as shown in the screenshot below

    LedgerJournalTrans      ledgerJournalTrans = args.getThis();
    info(strFmt('Credit Amount is %1',ledgerJournalTrans.AmountCurCredit));



Testing:

Now, to test your code,
go to General Ledger | Journal Entries | General Journal

create a new journal, click on lines, and create a new line.
On saving, the system should inform that error "Credit Amount is X",
as shown in the following screenshot:




Monday, October 28, 2019

Pre Event Handler

In Dynamics 365 F&O we are not allowed to add our custom logic in between the core logic but we can execute our custom logic before and after the core logic and this can be achieved by using the Event handlers.
Microsoft® recommends usage of event handlers in every possible place because it is the best and safest way to customize any existing functionality to accommodate user requirements.

The are two types of Event Handlers

Pre-Event Handler    (Executed before the core logic)

Post-Event Handler   (Executed after the core logic)
Click here for more details about event handlers.

In this blog i will show you how can we create a Pre-Event handler step by step.

Examples of Pre-Event Handler:

Let’s take an example of table "LedgerJournalTrans" it has a method of "Insert" and we want to verify the value of field "AmountCurCredit" that it should not be greater than 3000.

So here we can use the pre event handler which will be executed before the core insert method.
You can use the Pre-Event Handler for following purposes
1) Validation
2) update value
3) Assign values etc..

please follow the following steps
  1. Add a new class in your project and give it a proper name as "LedgerJournalTrans_Handler" or "LedgerJournalTrans_EventHandler"
  2. Search the "LedgerJournalTrans" in the Tables node of Application Explorer and right click on the table then click on "Open designer"

  3. Open the "Methods" node of table then find the "insert" method and right click on the method then go to "Copy event handler method" then click on "Pre-event handler"

  4. Now come to the class "LedgerJournalTrans_Handler" and "Paste" then your class look like as shown below

  5. Now add the following code in your method and your final class look like as shown in the screenshot below
    LedgerJournalTrans      ledgerJournalTrans = args.getThis();
    if(ledgerJournalTrans.AmountCurCredit > 3000)
    {
                Global::error('CreditCard amount must be less than 3000');
    }

Testing:
Now, to test your code,
go to General Ledger | Journal Entries | General Journal


create a new journal, click on lines, and create a new line with the credit amount "3001".
On saving, the system should throw the error
"Credit Amount must be less than 3000"
,
as shown in the following screenshot:



Monday, October 21, 2019

Update method parameters using Pre Event Handler

Update method parameters using pre event handler

Some time we need to update methods parameters value. In this blog i will show you that how can we achieve this using "Pre Event Handler" in Microsoft Dynamics 365 Finance and Operations.

Example:
Suppose we have multiple designs for "FreeTextInvoice" Report and we always want to pick the Design from "PrintManagement".
For achieve this requirement i am using out of the box form and create the "pre-event handler" of it's method to updates its parameters value

Form Name : CustFreeInvoice
Method Name : printInvoice



Please follow the following steps
  • Go to AOT using Visual Studio and Search "CustFreeInvoice" in Application Object Tree
  • Right click on CustFreeInovice inside the Forms node and click on "Open designer"
  • Search "printInvoice" in the Searchbar of the form
  • Right click on the "printInvoice" method then click on "Copy event handler method" then click on "Pre-event handler"
  • Create new class as "CustFreeInvoiceHandler" and Paste event handler in this class it looks like as shown below
  • Now add the following code to update the value of the parameter





RDP Framework classes

Controller Class

Controller class is used to control the report execution as well as pre-processing of the report data.
The SSRS reporting framework uses this class to modify the report dialogs, calling the SQL Server reporting services, as well pre-processing parameters for the report.

Following are the scenarios where Controller class can be used:
  • Modifying a report query based on the input data
  • Modifying report contract data based on the input data
  • Control a report parameters dialog
  • Open different reports/designs from the same menu item based on the input data
  • Reports that are opened from a form
"To create a controller class, extend it with SrsReportRunController"




Contract Class

A Contract class is used to define one or more parameters in the SSRS Report.
This class contains parm methods with the DataMemberAttribute these methods specifies data member of the contract class.
We have to use following attributes in Contract class



  • DataContractAttribute [ Indicates that this is a Contract ]
  • DataMemberAttribute [ Indicates that it is a contract member used on every parm method ]
  • SysOperationLabelAttribute [ label for the data members in the data contract ]
  • SysOperationHelpTextAttribute [ help text for the data members in the data contract ]
  • SysOperationGroupAttribute [ Groups the data members of the data contract ]
  • SysOperationDisplayOrderAttribute [ arrange data members in particular order ]
  • SysOperationContractProcessingAttribute [ Bind UIBuilder Class ]
[Note : Contract class can also bind itself to a UIBuilder class using attribute]



UIBuilder Class

A UIBuilder class is used to customize the report dialog through which a user opens the SSRS report.
The UIBuilder class extends the SRSReportDataContractUI class 
Following are the scenarios where Controller class can be used:
  • To create custom lookup


RDP Class

A RDP Class is a major class in RDP Framework.RDP class is used to process the data and stored the data into temporary table which displays the record in the report

The RDP Class uses two important attributes:
  • SRSReportQueryAttribute : This attribute is used to specify the AOT Query which is used in the report.
  • SRSReportParameterAttribute : This attribute is used to link the data contract class (in which we define the parameters) with the report
    This attribute is define at the bigninng of the RDP class



Monday, July 22, 2019

Event Handlers

In Dynamics 365 F&O we are not allowed to add our custom logic in between the core logic but we can execute our custom logic before and after the core logic and this can be achieved by using the Event handlers.
Microsoft® recommends usage of event handlers in every possible place because it is the best and safest way to customize any existing functionality to accommodate user requirements.

The are two types of Event Handlers

Pre-Event Handler    (Executed before the core logic)

Post-Event Handler   (Executed after the core logic)


You can use Event Handler for following elements

1) Tables
2) Classes
3) Forms

Examples of Pre-Event Handler:

Let’s take an example of table "LedgerJournalTrans" it has a method of "Insert" and we want to verify the value of field "AmountCurCredit" that it should not be greater than 3000.

So here we can use the pre event handler which will be executed before the core insert method.
You can use the Pre-Event Handler for following purposes
1) Validation
2) update value
3) Assign values etc..

click here for more detail about "Creating a Pre-Event Handler"

Example of Post-Event Handler:

Let’s take the same example as above but here we just need to warn the user after the record is "Inserted" so we use the post event handler which throws the warning that the limit is exceeded.
So here we can use the Post Event Handler.

You can use the Post-Event Handler for following purposes
1) Update Values
2) Warnings etc..

click here for more details about "Creating a Post Event Handler"






Tuesday, June 25, 2019

Add methods to tables through extension

Creating table extension does not allow you to add new methods.
As you can see in the screenshot below.
When i right clicked on Methods node of table extension there is no option available to add
" New Method ".




So to add a new method in standard table we need to follow the following steps.
  1. Create an Extension class for table
    Right click on your project then Add > New Item > Code > Class > Name "SalesConfirmHeaderMy_Extension" > AddThis class is called "augmentation class" of table "SalesConfirmHeader"



  2. There are a few rules for augmentation classes outlined by Microsoft
      1. They must be final.
      2. They must be suffixed by _Extension
      3. They must be decorated with the [ExtensionOf()] attribute.
  3. So first we need to fulfil these rules. Our augmented class will look like below (screenshot)




  4. Now you can add new methods to the augmentation class.These methods will then appear in intelliSense for variable of the "SalesConfirmHeadrTmp" table.
    In my case i added a "myTestMethod()" which sets the value in my custom field
    "MyStrField"of that table.



     Note : please visit this link to add a new field in standard table using extension approach
  5. Now create a run-able job just to verify that custom added method is displaying in the intellisense or not.
    Right click on your project then Add > New Item > Code > Runnable Class (Job) > Name "VerifyMethodJob" > Add

  6. Now create a variable "salesConfirmTable" for table "SalesConfirmHeaderTmp"
    and as you can see in the screenshot below that custom added method is displaying in the intellisense which was defined in the augmentation class



Monday, June 24, 2019

Table extension to add a field

Table extensions provide a way to add fields to a table without over-layering.
This means that we don't need to perform a code merge when the base package is changed.

We will add a field to the " SalesConfirmHeaderTmp " table, which we will use in the How to customize a document layout without an over-layer recipe.

To add a field to a table as an extension, follow these steps:
  1. Run Visual Studio and create your project.
  2. Locate the " SalesConfirmHeaderTmp " table in the Application Explorer as shown in the screen shot below.

  3. Right-click on it and choose Create extension.
    Note: Please make sure that your project model should be correct.
    In the screenshot below my project model is " Fleet Management " which is incorrect.
    " Fleet Management " is not a extension model of " Application Suite " model that is why the " Create extension " is non clickable.



  4. Right-click on your project and go to " Properties "

  5. Property window will appear then select your appropriate model as shown in the below screen shot
    Note: " AXGuru_Customization " is my custom model which i created as an extension of " Application-Suite " Model
    For create a custom model visit this link click here


  6. Follow the step 3 again and you will see that " Create Extension " option is clickable



  7. Click on " Create Extension ".
  8. " SalesConfirmHeaderTmp.Extension " Table is added in your project,
    now right click on it and click " Open "

  9. Right click on the " Fields " note,
    Click " New " then select the type ( example : String, Integer,Real etc )

  10. In my case i am adding the " String " type field.
    and set it's properties.
    Name : Axg_Description
    EDT : Description

Post Event Handler

In Dynamics 365 F&O we are not allowed to add our custom logic in between the  core logic  but we can execute our custom logic before ...