Notifications – Business Central

Today in this post we will discuss about Notification and how to implement.

First let us see, what are Notifications?

  • Non-intrusive message
  • Differs from the message initiated by the MESSAGE method.
  • Contextual
  • You can specify up to 4 actions
  • User can ignore and continue to work, doesn’t lock the user for immediate response.
  • Works with any client

Messages are modal, which means users are typically required to address the message and take some form of corrective action before they continue working. On the other hand, notifications are non-modal. Their purpose is to give users information about a current situation, but do not require any immediate action or block users from continuing with their current task.


Tips for Create Notifications

  • Always use a unique ID, can be any GUID
  • ADDACTION points to a function
  • Arguments are case-sensitive literal
  • Functions must be global
  • Function must accept a Notification as parameter
  • Use SETDATA and GETDATA to exchange information between the sending and handling function.

Using Notification and NotificationScope data types and methods you can add code to send notifications to the users.


MyNotification : Notification;

Available methods are as below:

Method Description
MESSAGE Specifies the content of the notification that appears in the UI.

MyNotification.Message := ‘This will be shown as Notification’

SCOPE Specifies the scope in which the notification appears.

MyNotification.SCOPE := NOTIFICATIONSCOPE::LocalScope;

SEND Sends the notification to be displayed by the client.


ADDACTION Adds an action on the notification.

MyNotification.ADDACTION(‘Action 1’, CODEUNIT::”My Action Handler Codeunit”, “RunMyAction1’);

SETDATA Sets a data property value for the notification


GETDATA Gets a data property value from the notification.


RECALL Recalls a sent notification.

Without going further any more in theory, let’s check how we can enable Notification.

Step – 1

Create a Codeunit to handle the Actions for Notification.

As usual we create a new Codeunit in our Extension Project.

codeunit 50101 NotificationRaiseAndHandel

Step – 2

Raise the Notification

You can Raise the Notification on Specific Page or can subscribe to the Events of that Page and write your code.

I am using the Subscription way to Raise my Notification.

For Demo purpose I am subscribing to OnOpen Event of the Page, in actual you need to decide from which action/event you wish to raise this Notification.

Code are self-explanatory, so no need special commentary.

  • I am checking for Company Info Setup we created in our earlier post if it is complete or not and then inform user about you Company Information is not completed and give him the option if he wish to complete that activity.

[EventSubscriber(ObjectType::Page, Page::”Sales Order”, ‘OnOpenPageEvent’,

”, true, true)]

local procedure CheckCompanyInfo(var Rec: Record “Sales Header”)


CompInfo: Record “Company Information”;

MyNotification: Notification;


if compinfo.get then

if ( <> ”) and (compinfo.”E-Mail” <> ”) then


MyNotification.Id := FORMAT(CreateGuid, 0, 9);

MyNotification.Scope := NotificationScope::LocalScope;

MyNotification.Message := ‘Company Information Incomplete.’;

MyNotification.AddAction(‘Open Company Information’, 50101,




  •  I am checking the Credit Limit of the customer if it is low, attracting attention towards it and giving him chance to update the Credit Limit.

   [EventSubscriber(ObjectType::Page, Page::”Sales Order”, ‘OnOpenPageEvent’,

”, true, true)]

local procedure CheckCreditBalance(var Rec: Record “Sales Header”)


Customer: Record Customer;

MyNotification: Notification;

Text001: TextConst ENU = ‘Balance Exceeds Credit Limit.’;

Text002: TextConst ENU = ‘Wish to change Credit Limit?’;


Customer.Get(Rec.”Sell-to Customer No.”);

Customer.CalcFields(“Balance (LCY)”);

if Customer.”Balance (LCY)” > Customer.”Credit Limit (LCY)” then begin


MyNotification.Scope := NotificationScope::LocalScope;

MyNotification.SetData(‘CustomerNumber’, Customer.”No.”);

MyNotification.AddAction(Text002, 50101, ‘OpenCustomer’);




Step – 3

Handle the Action

Write the procedure which will respond to Actions.

   procedure DisplayCompanyInfoWizard(MyNotification: Notification)


CompInfo: Record “Company Information”;




   procedure OpenCustomer(MyNotification: Notification)


CustomerNo: Text;

Customer: Record Customer;

CustomerCard: Page “Customer Card”;


CustomerNo := MyNotification.GetData(‘CustomerNumber’);

if Customer.Get(CustomerNo) then begin



end else begin

ERROR(‘Customer %1 not found.’, CustomerNo);



Here is the complete Code:


Step – 4

Publish the Extension

To Publish choose AL:Publish from command Pallet.

Step – 5

Test the Solution.

Open the Sales Order Page and you will see the Message as shared above. Keep in mind this is just for demo, this is not the right place from where such Notifications will be raised, in real scenario you need to raise these Notifications from appropriate action/event. Now you know the basics can build your own logic around.

Will come up with some more Development Tips in my future posts.

Enjoy coding and learning. Take Care of yourself.


Event driven Programming – Business Central

You can use events to design your application. Below are the benefits of using this model.

  1. You can lower the cost of code modifications and upgrades.
  2. You can customize functionality without modifying the original application.
  3. Your program will react to specific actions or behaviours of original application.


The following table describes all the different event types:

Event types Description
BusinessEvent Specifies the method to be business type event publisher.
IntegrationEvent Specifies the method to be integration type event publisher.
Global Global events are predefined system events.
Trigger Trigger events are published by the runtime.

You program events in the application to run customized behaviour when they occur.


What are Events?

A thing that happens. Event is declared by an AL method, which is referred to as event publisher function. Publisher method have only signature only and does not execute any code.

Publisher is the object that contains event publisher methods that declares the event. It serves as hook-up point in application, where subscribers use these points to extend the functionality, without even making any changes to the base application.

Only publishing an event do nothing in application, these events must be raised for subscribers to respond.

Especially Business and Integration type events must be published and raised, you need to create event publisher functions and add them to the objects manually.

Trigger events which occurs on Table & Page operations, are automatically published and raised by system at runtime, so no coding is required to publish them.

Subscriber is an AL method that subscribes to even publisher method, and logic to handle the event is implement.


Creating an event publisher method to publish business and integration events

Creating event publisher method is similar to other methods you define in AL. In addition some specific properties and few restrictions.

  • Can not include any code except comments.
  • You cannot define return values, variables or text constants.

You can define event publisher in any objects new or in existing objects and of any type of objects like codeunit, page or table.

If you define even as local then it will not be available for subscribers.


local procedure MyProcedure()




local procedure MyProcedure()



Feel free to add as much of parameters and of any type as required. However it is advised not to include unnecessary parameters to Business events.

Raising Events

You need to modify the application to raise the event where ever it is needed. You call the event publisher method, same way you call any other methods in AL.

When the execution hits the evet publisher method, all event subscriber method that subscribe to the event are executed. Limitation will be you can not specify the order in which subscriber method will run, subscribers will be picked one at a time and in random order.


Subscriber Method

You can create new or use existing codeunits to define subscriber methods.

[EventSubscriber(ObjectType::Codeunit, Codeunit::, ‘OnSomeEvent’, ‘ElementName’, SkipOnMissingLicense, SkipOnMissingPermission)]

local procedure MyProcedure()



Add code to the method for handling the event.

Don’t worry at this point we will go through complete process programmatically in our next upcoming posts.

How to find which event to subscribe, and where to write our code.

Similar to earlier days we used Code Coverage, same way we have Event Recorder in Business Central.

Search for Event Recorder in RTC or alternatively you can launch from VS Code from Command Palate AL: Open Events Recorder.

Let’s look at a small example of finding Events.

I want to know what all events hit or available to subscribe when Sales-Order is Re-Opened.

Step-1: Open the Event Recorder and Click on Start.


Step-2: Perform Sales-Order -> Reopen

Step-3: Click on Stop.


Step-4: Scan from the list of events that you find suitable, to know how to subscribe to that event you can find AL Code. (Get AL Snippet)


All the recorded events display in the order they were called. The Event Recorder page provides information on the events that were raised including the details whether the raised events were trigger events or custom events. The custom events are either Business Events or Integration Events.

You can identify the Event types, additionally, you can discover which object types and methods raised the events with the details like calling methods, object types, and object names.

Readiness to Event:

  • Redesign your on prem to an event-based approach in C/AL.
  • This will prove to be best preparation for moving to VS Code AL extension.
  • You will be able to find any issues in your code that you need to refactor.
  • Next step will be to Lift your on prem product to VS Code AL extension.
  • Then extension can be published as a MSDY365 Business Central app.

Now you know about basics of Events. Understand Publisher, Raising Events and Subscribing to Events. Also how to trace and find suitable events to subscribe for your customization over base application.

Before we end the post let’s have a Recap to Events


  • Announcement by the application
  • Function without code
  • Exposes the event to the outside


  • Specifies exactly when the event happens
  • Call to the Publisher Function


  • React to the event
  • Must be in codeunit, tableextension or pageextension.

Note: Raise order specified in code, Subscribe order undefined.

We will look into practical approach in our next post.


Which Object types you can Include & Restrictions applicable to C/AL code in Extension Packages

For Overview, please see my earlier post Introducing Extensions in Microsoft Dynamics NAV 2016

When you create extension package you can include new as well as modified objects.

In Microsoft Dynamics NAV 2016, these object types can be added and included in an extension:

  • Pages
  • Tables
  • MenuSuites
  • Codeunits

You can modify these existing object types as permitted by your license:

  • Pages
  • Tables
  • Action Items

You will not be able to add or modify any other object types in this version.

You are not allowed to delete any existing objects.

You will also need to be sure not to modify any existing C/AL code, including code in codeunits and in triggers on existing objects.

In case you want to modify existing code, use the new C/AL eventing model.

To know more about Events see by earlier posts:

  1. Events in C/AL Navision 2016
  2. Implementing Events in Navision 2016

This restriction is only on existing code and objects. However New pages, tables, and so on, can contain C/AL code as it is considered part of the new object.

Implementing Events in Navision 2016

Recall from my earlier post for description of Events – Events in C/AL Navision 2016

Here in this post we will see how to implement the same.

This could be helpful in situation where throughout the system you wish to have similar behaviour on specific condition. In general we will have to write code in every object with same set of logic, variables, and functions and so on.

Although still in this case too we will require to add code to every object, but only one time.

Think of you need to enhance or make changes in behaviour again you will have to go through each objects and do the required change. But using this feature we can keep it centralized and manage from single place, without going through each objects again.

Here below I am taking example one explained by Microsoft help basic concept, will come up with my version with some more effective usage later sometime.

When users change the address of a customer, you want to check that the address does not include invalid characters, which in this walkthrough is a plus sign (+).

To accomplish this, you will publish an event that is raised when the Address field on page 21 Customer Card is changed.

To handle the event when it is raised, you will add an event subscriber function that includes logic that checks the address value and returns a message to the user if it contains a plus sign.

Publishing the Event

To publish an event, you create a C/AL function that is set up to be an event publisher. An event publisher function can be added in any object, such as a codeunit, page, or table.

In this procedure we will add the event publisher function to a new codeunit, in which you can potentially add more event publisher functions for other events later.

Because you might want to change this event implementation in the future, you decide to create an integration event type.

The event publisher requires a single text parameter for handling the address of the customer.

Create a new codeunit

The codeunit for the event publisher I have created 50000 – Event Publisher.

Now we will add the event publisher function to publish the event.

To create the event publisher function to publisher the event

  • Define a function OnAddressLineChanged.
  • Open the properties for the OnAddressLineChanged function, select the function, and then in the View menu, choose Properties. Set the properties as follows:
  • Set the Local property to No.

Setting this property makes the function available to be called from the other objects.

  • Set the Event property to Publisher. This makes the function an event publisher.
  • Set the EventType property to Integration.
  • Close the Properties


  • Add a local parameter to the function for the address of the customer as described in the following steps:
  • On the Functions tab, select the OnAddressLineChanged function, and then choose the Locals

The C/AL Locals window opens.

  • On the Parameters tab, in the Name field, enter line.
  • Set the DataType field to Text.
  • Set the Length field to 100.



An event publisher function cannot have a return value, variables, or text constants; otherwise you will not be able to compile the function.

The new function appears in the C/AL Editor with the following signature:

[IntegrationEvent] OnAddressLineChanged(line : Text[100])

You can now raise the event in the application.

Raising the Event

After creating the event publisher function to publish the event, now we will add code to the application to raise the event where it is required.

In this case, the event will raise when the Address field is changed on the page 21 Customer Card.

Therefore, we will add code to the Address – OnValidate() trigger in C/AL code of the page. Raising an event basically involves calling the event publisher function that publishes the event.

To raise the event

  • In the development environment, open page 21 Customer Card as follows:
  • Add a C/AL variable that specifies the object that publishes the event. In this case, the event publisher object is codeunit 50000 Event Publisher, which contains the event publisher function OnAddressLineChanged that you created in the previous procedure.


  • In C/AL code, add the following code on the Address – OnValidate() trigger to raise the event:


This calls the event publisher function to raise the event.

  • Save and compile the changes to the page.

The event can now be subscribed to and handled.

Subscribing to and Handling an Event

Once an event has been published you can add code to the application that subscribes to and handles the event when it is raised.

For example, in this case when a user changes the address of a customer (the event), you want code that checks that the value does not contain a plus sign.

Subscribing to and handling an event is accomplished by creating a C/AL function that is set up as an event subscriber and subscribes to a specific event (defined by an event publisher function). The event subscription function contains the application logic for handling the raised event.

In this case, we will create an event subscriber function that subscribes to the OnAddressLineChanged function in codeunit 50000 Event Publisher.

Unlike an event publisher function, an event subscriber function can only reside in a codeunit object. This procedure will add the event subscriber function to a new codeunit, in which you can potentially add more event subscriber functions for other events later.

To create a new codeunit

  • In the development environment, create a new codeunit that has the ID 50001 and the name Event Subscriber.

To create the event subscriber function to subscribe to and handle the event

  • Create Function CheckAddressLine.


  • Choose Properties. Set the properties as follows:
  • Set the Event property to Subscriber to make the function an event subscriber.
  • Set the EventPublisherObject property to Codeunit My Publishers.

This is the codeunit that contains the event publisher function (OnAddressLineChanged) that you want to subscribe to.

  • In the EventFunction property, select the OnAddressLineChanged integration event.

This field reads all the published events in the event publisher object.


When you get a message that asks whether you want to overwrite the edited function’s signature, choose Yes to continue.

  • A local parameter that has the name line and the data type Text has been automatically added to the new CheckAddressLine
  • The new function appears in the C/AL Editor with the following signature:

LOCAL [EventSubscriber] CheckAddressLine(line : Text[100])

You can now add code to handle the event.

  • To handle the event, add the following code to the CheckAddressLine function in the C/AL editor:

IF (STRPOS(line, ‘+’) > 0) THEN BEGIN

ERROR(‘Cannot use a plus sign (+) in the address [‘ + line + ‘]’);


This code checks the value of the Address field on page 21 Customer Card when is has been changed and returns a message if the value contains a plus sign.

Viewing the New Event Subscription

After you create an event subscriber, you can view information about it in page 9510 Event Subscriptions. This page provides information about all the current event subscriptions in the application. You can open this page directly from the development environment or from a Microsoft Dynamics NAV client.

To view the event subscription from the development environment

  • On the Tools menu, choose Debugger, and then choose Event Subscriptions.


To view the event subscription from a Microsoft Dynamics NAV client

  • Start the Microsoft Dynamics NAV client.
  • In the Search box, enter Sessions, and then choose the related link.


The Even Subscription Window will look like:

Testing the Event

To test the event implementation, you can run page 21 Customer Card from the development environment.

  • In the Address field, add a plus sign, and then choose the OK

The following message appears:

Cannot use a plus sign (+) in the address [].

[] contains the value of the Address field.

I will come up with more details on this topic later in my future posts.

Events in C/AL Navision 2016

By implementing events in C/AL code, you can design applications to react to specific actions or behaviour that occur.

Events enable you to separate customized functionality from the application business logic.

By using events in the application where customizations are typically made, you can lower the cost of code modifications and upgrades to the original application.

Events can be used for different purposes, such as generating notifications when certain behaviour occurs or the state of an entity changes, distributing information, and integrating with external systems and applications.

How Events Work

There are three major participants involved in events: the event, a publisher and a subscriber.

An event is the declaration of the occurrence or change in the application. An event is declared by a C/AL function, which is referred to as an event publisher function. An event publisher function is comprised of a signature only and does not execute any code.

A publisher is the object that contains event publisher function that declares the event. The publisher exposes an event in the application to subscribers, essentially providing them with a hook-up point in the application. An event is raised by adding logic to the application that calls into the publisher to invoke the event (the event publisher function). There are three different event types: business, integration, and trigger events.

Business and integration type events must be explicitly declared and published, which means that you must create event publisher functions and add them to objects manually. On the other hand, trigger events, which occur on table and page operations, are published and raised implicitly by the Microsoft Dynamics NAV runtime. Therefore, no coding is required to publish them.

A subscriber listens for and handles a published event. A subscriber is a C/AL function that subscribes to a specific event publisher function and includes the logic for handling the event. When an event is raised, the subscriber function is a called and it code is run.

How to Implement Events

Implementing events in Microsoft Dynamics NAV consists of the following tasks:

  1. Publish the event. For business and integration events, create and configure a function in an application object to be an event publisher function.
  2. Raise the event. Add code that calls the event publisher function..
  3. Subscribe to the event. At the consumer end, add one or more subscriber functions that subscribe to published events when they are raised.

Will come up with how to practically use it in my upcoming posts.


Most of the contents you find in this blog will be either inherited from MSDN or Navision Developer IT Pro Help. Some places images are also directly taken from these sites. Purpose is simple to try those stuffs and re-produce adding few things as per my understanding to make easy understanding for others and quick reference.

Here nothing under my own brand or authorship of the content. At any point of time we are just promoting Microsoft stuffs nothing personnel with same.

Hope stuffs used here will not violate any copyright agreement with them. In case by mistake or in-intestinally it happens and the Microsoft feels these should not be used Microsoft have full right to inform me about same and will be glad to take down any such content which may be violating the norms.

Purpose is to promote Navision and share with community.

FB Profile

Like FB Page

%d bloggers like this: