Saturday, April 27, 2019

How to subscribe to an Event in Dynamics 365 Business Central?

Hi ,

What is an Event?

An Event is a function provided by Microsoft to help developers for minimizing code in Standard Object for development.

So to identify which event you want to use , first we need to check the standard event available to subscribe. For details of Events you can follow :

How to subscribe to an event in AL Code?

Here I want to update Posting Description field with Vendor Name in Purchase Invoice Page. So I had subscribed to 2 events provided by Microsoft.

Here I had subscribed to events of Object Type Table. You can use Snippet teventsubs

codeunit 50100 CustomCodeunit
trigger OnRun()


[EventSubscriber(ObjectType::Table, DATABASE::"Purchase Header", 'OnAfterInitRecord', '', true, true)]
local procedure OnAfterInitRecord(VAR PurchHeader: Record "Purchase Header")
PurchHeader.Validate("Posting Description", PurchHeader."Buy-from Vendor Name");

[EventSubscriber(ObjectType::Table, DATABASE::"Purchase Header", 'OnAfterCopyBuyFromVendorFieldsFromVendor', '', true, true)]
local procedure OnAfterCopyBuyFromVendorFieldsFromVendor(VAR PurchaseHeader: Record "Purchase Header"; Vendor: Record Vendor)
PurchaseHeader.Validate("Posting Description", Vendor.Name);

myInt: Integer;

No comments:

Post a Comment