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
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
- Add a
new class in your project and give it a proper name as "LedgerJournalTrans_Handler" or "LedgerJournalTrans_EventHandler"
- Search
the "LedgerJournalTrans" in
the Tables node of Application Explorer and right click on the table then click
on "Open designer"
- 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"
- Now come to the class "LedgerJournalTrans_Handler" and "Paste" then your class
look like as shown below
- 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
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:

On saving, the system should inform that error "Credit Amount is X",
as shown in the following screenshot:
