How-to: Add your notification to My Notifications

In my post How-to: Create Notifications – Steps to Take I introduced a step-by-step recipe that can help you to efficiently create a (non-intrusive) notification. I gladly used the YouTube video Develop SAAS user experiences for Dynamics 365 Business Central by Daniel Rimmelzwaan to illustrate this. Doing this I stuck to his example without adding anything, but the step-by-step approach.

In this post I would like to extend the example allowing you to add your notification to My Notifications and enabling the user to turn on or off your notification. To achieve this I need to do three additional steps, continuing the numbering of the steps as introduced in How-to: Create Notifications – Steps to Take.

  1. Add notification to My Notifications
  2. Create IsEnabled check method
  3. Call IsEnabled in send-or-recall method

6. Add notification to My Notifications

A notification is being added to My Notifications based on the discovery design pattern. This can easily be achieved with a subscriber to the OnInitializingNotificationWithDefaultState publisher on the My Notifications page.

[EventSubscriber(ObjectType::PagePage::”My Notifications”, ‘OnInitializingNotificationWithDefaultState’, false, false)]
local procedure OnInitializingNotificationWithDefaultState()
var
    MyNotifications: Record “My Notifications”;
begin
    MyNotifications.InsertDefaultWithTableNum(NotificationIdLbl,
        CompanyInfoMissingNotificationMsg,
        CompanyInfoNotificationDescriptionTxt,
        Database::”Company Information”);
end;

Note that we reuse the NotificationIdLbl  and CompanyInfoMissingNotificationMsg labels already created as part of the previous steps and that an additional label is needed.

var
    CompanyInfoNotificationDescriptionTxt: Label ‘Show warning when the company information is not complete.’;

7. Create IsEnabled check method

We need a method that determine whether the notification is enabled or not (by the user).

local procedure IsCompanyInfoNotificationEnabled(CompanyInfo: Record “Company Information”)Boolean
var
    MyNotifications: Record “My Notifications”;
begin
    exit(MyNotifications.IsEnabledForRecord(NotificationIdLbl, CompanyInfo));
end;

8. Call IsEnabled in send-or-recall method

And finally we need to call the IsEnabled method by adding the following tow lines to the SendOrRecallCompanyInfoMissingNotification methodthat was created in step 4, after the company record was gotten.

if not IsCompanyInfoNotificationEnabled(CompanyInfothen
    exit;

Now you have a complete action plan to create a notification and enable the user to configure whether it will appear or not. Have fun.

Update 20201119

Waldo has added this a a snippet tmynotificationscodeunitwaldo to his CRS AL Language Extension.

3 Comments

  1. Really helpful

  2. I’m curious why the event is managed on the page instead of using a function from the table. Wouldn’t it be better to use a function from the “My Notifications” table to initialaize the notification, rather than relying on a page event?

  3. Hi Konrad, only seeing your comment just now. Apology for the silence.

    Not sure if this it true, but I believe that we do not have access to the table. However this is the only publisher available (at that time).

Leave a Reply

Your email address will not be published. Required fields are marked *