Skip to the content

News

How-to: Create Notifications – Steps to Take

In a recent VSCode/AL update training the topic , as part of , was tackled. After a short introduction of what these notifications (functionally) are about I explained and demoed how to develop them. Inviting the attendees thereafter to pose their questions, one of them, a seasoned C/SIDE developer whom I will call Bogdan, marked that he had been implementing them a couple of times and still had issues with the different parts that have to be developed. He asked: "Could you give me a clear overview on what steps I have to take?"

It was special to experience how this resonated i me as that was exactly what I ran into when preparing this part of the training. Notifications as a functional feature are efficient, simple and powerful. To code them isn't surely rocket science, but to have a clear overview what is needed and how it can be structured can indeed be somewhat muddy. Triggered by Bogdan's question I came up with the following steps:

  1. Create method NotificationId
  2. Create sender method
  3. Create recaller method
  4. Create method with send-or-recall logic
  5. Trigger send-or-recall method in event subscribers to relevant publishers

Let me elaborate on these steps by means of an example taken from Daniel Rimmelzwaan's video l.

1.Create method NotificationId

Each notification should a unique id being a Guid. For reusibility ease of use you need to create a function that will allow you to assign and retrieve this id.

local procedure NotificationId()Guid;
begin
    exit('fab25372-5716-4fad-b6ee-20c6d0f5105c');
end;

Note that you have to fill in your own, unique .

2.Create sender method

The code part that sets up your notification is called the . This is how it could look like:

local procedure SendCompanyInfoMissingNotification()
var
    CompanyInfoMissingNotification: Notification;
begin
    CompanyInfoMissingNotification.ID := NotificationId();
    CompanyInfoMissingNotification.Message := CompanyInfoMissingNotificationMsg;
    CompanyInfoMissingNotification.Scope := NotificationScope::LocalScope;
    CompanyInfoMissingNotification.AddAction(OpenCompanyInfoTxt, Codeunit::"Notication Company Info", 'ShowCompanyInfomationWizard');
    CompanyInfoMissingNotification.Send();
end;

3.Create recaller method

Each sender should in general be accompanied by a recaller:

local procedure RecallCompanyInfoMissingNotification()
var
    CompanyInfoMissingNotification: Notification;
begin
    CompanyInfoMissingNotification.ID := NotificationId();
    CompanyInfoMissingNotification.Recall();
end;

4.Create method with send-or-recall logic

Given sender and recaller we can now build the send-or-recall logic that will define whether a notification should be sent or recalled.

local procedure SendOrRecallCompanyInfoMissingNotification()
var
    CompanyInfo: Record "Company Information";
begin
    CompanyInfo.Get();
    if (CompanyInfo.Name = '') or (CompanyInfo."E-Mail" = ''then
        SendCompanyInfoMissingNotification()
    else
        RecallCompanyInfoMissingNotification();
end;

5.Trigger send-or-recall method in event subscribers to relevant publishers

Eventually, now having all logic in place to create a notification and determine to get it shown, the last part we need to setup is when it shouild be triggered.

[EventSubscriber(ObjectType::PagePage::"Sales Order", 'OnAfterGetCurrRecordEvent''', false, false)]
local procedure CompanyInfoMissingNotifOnAfterGetCurrRecordEvent(var Rec: Record "Sales Header")
begin
    SendOrRecallCompanyInfoMissingNotification();
end;

Hope this makes sense and can be of help.

How-to: Create Notifications – Steps to Take (1)

In a recent VSCode/AL update training the topic , as part of , was tackled. After a short introduction of what these notifications (functionally) are about I explained and demoed how to develop them. Inviting the attendees thereafter to pose their questions, one of them, a seasoned C/SIDE developer whom I will call Bogdan, marked that he had been implementing them a couple of times and still had issues with the different parts that have to be developed. He asked: “Could you give me a clear overview on what steps I have to take?”

It was special to experience how this resonated in me as that was exactly what I ran into when preparing this part of the training. Notifications as a functional feature are efficient, simple and powerful. To code them isn’t surely rocket science, but to have a clear overview what is needed and how it can be structured can indeed be somewhat muddy. Triggered by Bogdan’s question I came up with the following steps:

  1. Create function label NotificationId
  2. Create sender method
  3. Create recaller method
  4. Create method with send-or-recall logic
  5. Trigger send-or-recall method in event subscribers to relevant publishers

Let me elaborate on these steps by means of an example taken from Daniel Rimmelzwaan’s video l.

1.Create function label NotificationId

Each notification should have a unique id being a Guid. For reusability ease you need to create a function label that will allow you to assign and retrieve this id.

local procedure NotificationId()Guid;
begin
    exit(‘fab25372-5716-4fad-b6ee-20c6d0f5105c’);
end;
var
    NotificationIdLbl: Label ‘b60c6e03-569c-411b-b65f-4df942d978e2’, Locked = true;

Note that you have to fill in your own, unique .

2.Create sender method

The code part that sets up your notification is called the . This is how it could look like:

local procedure SendCompanyInfoMissingNotification()
var
    CompanyInfoMissingNotification: Notification;
begin
    CompanyInfoMissingNotification.ID := NotificationId();NotificationIdLbl;
    CompanyInfoMissingNotification.Message := CompanyInfoMissingNotificationMsg;
    CompanyInfoMissingNotification.Scope := NotificationScope::LocalScope;
    CompanyInfoMissingNotification.AddAction(OpenCompanyInfoTxt, Codeunit::”Notication Company Info”, ‘ShowCompanyInfomationWizard’);
    CompanyInfoMissingNotification.Send();
end;

3.Create recaller method

Each sender should in general be accompanied by a recaller:

local procedure RecallCompanyInfoMissingNotification()
var
    CompanyInfoMissingNotification: Notification;
begin
    CompanyInfoMissingNotification.ID := NotificationId()NotificationIdLbl;
    CompanyInfoMissingNotification.Recall();
end;

4.Create method with send-or-recall logic

Given sender and recaller we can now build the send-or-recall logic that will define whether a notification should be sent or recalled.

local procedure SendOrRecallCompanyInfoMissingNotification()
var
    CompanyInfo: Record “Company Information”;
begin
    CompanyInfo.Get();
    if (CompanyInfo.Name = ) or (CompanyInfo.“E-Mail” = then
        SendCompanyInfoMissingNotification()
    else
        RecallCompanyInfoMissingNotification();
end;

5.Trigger send-or-recall method in event subscribers to relevant publishers

Eventually, now having all logic in place to create a notification and determine to get it shown, the last part we need to setup is when it should be triggered.

[EventSubscriber(ObjectType::PagePage::”Sales Order”, ‘OnAfterGetCurrRecordEvent’, false, false)]
local procedure CompanyInfoMissingNotifOnAfterGetCurrRecordEvent(var Rec: Record “Sales Header”)
begin
    SendOrRecallCompanyInfoMissingNotification();
end;

And of course add two labels for the notification and the action texts

var
    OpenCompanyInfoTxt: Label ‘Open company information’;
    CompanyInfoMissingNotificationMsg: Label ‘Company information is missing.’;

Hope this makes sense and can be of help.

Update 20201117

An interesting discussion occurred on my regarding this post. Have a look. One of the spin offs is that I replaced the NotificationId() function by a label, locked against translation

Update 20201119

Waldo has added this a a snippet tnotificationcodeunitwaldo to his

Using GitHub for DevOps

For the last 2 years we have had the Hands On Lab ( https://aka.ms/cicdhol ) in a few iterations using Azure DevOps as the platform. Latest revision was published a few weeks ago. There are however...()

Live Schedule for Period Ahead

Thanks to everyone who attended my live blog yesterday, and to everyone who subscribed. It was so encouraging to see that you like this idea. As announced yesterday, my live blog will run on a…

The post appeared first on .

Vjeko.com goes live

It’s time to turn a new page. You’ve noticed that I’ve been absent for a long time. No posts, no activity. Well, blogging takes time, and I am a sort of a perfectionist. Writing posts…

The post appeared first on .

Business Central V17.1 fails your pipeline .. and that’s OK

A few days ago, we upgraded our product from 17.0 to 17.1. We had been looking forward to this release, because we usually never release a product or customer on an RTM release of Business Central. So .. finally 17.1, finally we could continue to upgrade the product and start releasing this to customers before …

Top 5 things I miss in AL

The community often criticizes Microsoft for adding new platform features only when Microsoft needed them. Well, it has been a bit too harsh – Microsoft did add improvements in other situations, too. But still, if…

The post appeared first on .

How about Rollback in AL?

I’ve never truly understood why we could explicitly commit a transaction, but we could only implicitly roll one back. There is a universe of difference between throwing an error (and ending the call stack), and…

The post appeared first on .

Visualize app.json dependencies in VSCode (using GraphViz)

If you’ve been following the latest and greatest from Microsoft Dynamics 365 Business Central, you must be aware about “what’s cooking in Microsoft’s Lab“. In short, Microsoft is working on a possibility to generate a DGML file for your extension that you’re compiling. A DGML file is basically a file that contains all code cross …

DIRECTIONS4PARTNERS VIRTUAL CONFERENCE 2020 …will start tomorrow morning!

DIRECTIONS4PARTNERS VIRTUAL CONFERENCE 2020 …will start tomorrow morning! Directions For Partners Virtual Event 2020 will start tomorrow, just a little away! Below you will find all the sessions and the list of those that I consider most interesting (obviously “De Gustibus non disputandum est”, “Giulio Cesare”). It will definitely be a hit! See you there ...

L'articolo proviene da .