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 and let the users decide when do they want to complete the task.

In this example we will remind the user to fill the ‘Ship-to Adress’ table when creating a new customer and let them decide when do it.

Calling Event

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.

Notification Function

We will build the notification as the following:

  1. Write the message.
  2. Choose the scope of the notification.
  3. Set the data for the Action. This is needed when calling the action procedure.
  4. 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. Not sure why Microsoft would make it like that but that’s the way it is.
  5. Send the notification.

Notification Action

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 I 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:

Hope you find it useful.

How To Create Notification Actions In Business Central

Post navigation


Leave a Reply

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