Notifications have been around in Business Central for some time now. They are a really good non-intrusive way to make processes easier for users. In this post, I will introduce how notification actions can be used to interact with the notification. Letting the users decide when do they want to complete the task.
In the example below, we will remind the user to fill the ‘Ship-to Adress’ table when creating a new customer and let them decide when do it.
First we need to identify where do we want the notification to be sent to the user. In this case it will be the ‘OnAfterInsert’ event of the Customer table.
We will build the notification as the following:
- Write the message.
- Choose the scope of the notification.
- Set the data for the Action. This is needed when calling the action procedure.
- Add the action. Call the action procedure by choosing where the function is and the name of it. Note that it has to be in plain text.
- Send the notification.
The notification action procedure will check if the notification has any data (HasData), retrieve that data and use it to open the desired page. In this example we want the open the ‘Ship-to Address’ list of the customer we are creating:
As mentioned, the ‘OpenShipToAddress’ procedure has no references as it is called in this specific way:
procedure SendNotification(Rec: Record Customer) var xlNotification: Notification; begin xlNotification.Message('Don´t forget to add Ship-to Address'); xlNotification.Scope := xlNotification.Scope::LocalScope; xlNotification.SetData('ShipTo', Rec."No."); xlNotification.AddAction('Open Ship-to Address List', Codeunit::Functions, 'OpenShipToAddress'); xlNotification.Send(); end; procedure OpenShipToAddress(pNotification: Notification) var Customer: Record Customer; rlShipToAddress: Record "Ship-to Address"; plShipToAddress: Page "Ship-to Address List"; begin if pNotification.HasData('ShipTo') then begin Customer.Get(pNotification.GetData('ShipTo')); rlShipToAddress.SetRange("Customer No.", Customer."No."); plShipToAddress.SetTableView(rlShipToAddress); plShipToAddress.Run(); end; end;
Let´s try it out in this short clip:
That´s all. Hope you find it useful.