A notification is the non-blocking message at the top of the page with actions attached. It is the right tool for most of what developers use Message and Error for, and it is misused in both directions. When to use one, how to send it with data and actions, recall it, let users dismiss it permanently, and avoid the three ways it annoys people.
Between a silent system and a red error dialog there is the notification: the blue bar that says "this customer is over their credit limit" with a button to open the customer, without stopping the user. It is the mildest tool that still gets noticed, and the base application uses it for exactly that reason.
Something the user should know and may act on, but which does not prevent what they are doing: a warning, a suggestion, a status, an opportunity ("this item is available in another location"). Not for errors (the operation must not proceed), not for confirmations of success (a Message, or nothing), not for anything that requires an answer before continuing (a Confirm).
procedure WarnIfOverCreditLimit(Customer: Record Customer)
var
Notif: Notification;
begin
if not Customer.IsOverCreditLimit() then
exit;
Notif.Id := CreditLimitNotificationIdTok; // a fixed GUID, locked label
Notif.Recall(); // replace any existing one with this ID
Notif.Message := StrSubstNo(OverCreditLimitMsg, Customer."No.", Customer."Credit Limit (LCY)");
Notif.Scope := NotificationScope::LocalScope;
Notif.SetData(CustomerNoDataTok, Customer."No.");
Notif.AddAction(OpenCustomerLbl, Codeunit::"CON Notification Actions", 'OpenCustomer');
Notif.AddAction(DontShowAgainLbl, Codeunit::"CON Notification Actions", 'DisableCreditLimitNotification');
Notif.Send();
end;
The action codeunit's procedure receives the notification and reads the data back:
procedure OpenCustomer(Notif: Notification)
var
Customer: Record Customer;
begin
if Customer.Get(Notif.GetData(CustomerNoDataTok)) then
Page.Run(Page::"Customer Card", Customer);
end;
Give each kind of notification a fixed GUID as its ID. Then Recall() before sending removes the previous instance (so the user does not get five credit-limit bars from five lines), and you can recall it when the condition clears (the user corrected the quantity).
The base application's My Notifications page lists notifications a user can disable. Register yours: subscribe to OnInitializingNotificationWithDefaultState in Codeunit "My Notifications" and call MyNotifications.InsertDefault(Id, Name, Description, Enabled); before sending, check MyNotifications.IsEnabled(Id). Users who know what they are doing switch it off; new starters keep it. Microsoft's guidance is that any notification sent on a routine action should be disableable.
LocalScope (the page the user is on; the default) covers nearly everything. GlobalScope notifications persist across pages and are for things like "your export is ready"; use them rarely.
OnAfterGetRecord). Send on the action, or once per page open.Used well, one notification replaces a support ticket (the ten) and a training note. The error handling post covers the dialog you use when the operation genuinely has to stop.