Hello everyone
I'm a dynamics 365 junior developer, starting out with learning Business Central and AL.
I'm extremely curious about EventSubscribers and Triggers and the difference between them. I'm really sorry if this is asked frequently but I wasn't able to find a proper answer for my problem.
Which is the proper way of implementing a functionality? Trough the trigger or trough an EventSubscriber? Why?
Should I usually use a trigger and where I can't implement something trough triggers should I use an EventSubscriber? Should I always use EventSubscribers?
Below I have an example where I use a the OnBeforeInsertEvent trigger in an tableExtension and an EventSubscriber in a codeunit, for the same thing.
-------------------------------------------------------------------------------------------------------------------------
codeunit 50301 VendorTriggerExt
{
[EventSubscriber(ObjectType::Table, DATABASE::Vendor,'OnBeforeInsertEvent', '', true, true)]
procedure printMessage()
begin
Message('Hello!');
end;
}
-----------------------------------------------------------------------------------------------------------------------
tableextension 50302 VendorExt extends Vendor
{
trigger OnBeforeInsert()
begin
Message('hello!');
end;
}
----------------------------------------------------------------------------------------------------------------------------
Thank you for your time! I really want to learn good practices for using this technology. :D