How to create custom reminders and notifications
Glossary Item Box
Introduction
Starting with version 7.12.0, reminder and notification sending mechanics has been reworked in bpm'online.
Previously, to send a custom notification, you would have to:
- Creates a class that implements INotificationProvider interface or an inherited abstract BaseNotificationProvider class.
- Add logic for selecting custom notifications by bpm’online.
- Register a class in the NotificationProvider table.
The notifications were sent once a minute, calling all classes from the NotificationProvider table.
Starting with version 7.12.0, it is sufficient to create a notification or reminder with the needed parameters. After this, the application will either send the notification immediately, or display a reminder at the specified time.
To set up custom notifications:
1. Create a [Source code] schema in the custom package and define a class for generating the notification text and pop-up window. The class must implement the IRemindingTextFormer interface (declared in the IRemindingTextFormer schema of the Base package).
2. Replace the needed object (such as [Lead]) or specify notification sending logic in it.
3. Replace the reminder tab schema ReminderNotificationsSchema for displaying notifications for the needed object.
Case description
Create a custom reminder about opportunity actualization date in leads. The date must be specified in the [Next actualization date] field on the [Opportunity info] tab.
Source code
A package with implemented example is available for download via the following link.
Case implementation algorithm
1. Create a class for generating the reminder text and the pop-up window.
1. Add a [Source code] schema in the custom package (see “Creating the [Source code] schema”). Set the following properties (Fig. 1):
- [Title] – “Lead Reminding Text Former”.
- [Name] – "UsrLeadRemindingTextFormer”
Fig. 1. The [Source code] schema properties
2. Use the context menu of the [Structure] tab to add two localized strings (Fig. 2). Properties of the localized strings are described in table 1.
Fig. 2. Adding localized strings to schema
Table 1. Localized string properties
Name | Value |
---|---|
TitleTemplate | You need to update the sale |
BodyTemplate | Lead {0} requires update of sales information |
3. Add class implementation for forming reminder text and pop-up window:
namespace Terrasoft.Configuration { using System.Collections.Generic; using Terrasoft.Common; using Terrasoft.Core; public class UsrLeadRemindingTextFormer : IRemindingTextFormer { private const string ClassName = nameof(UsrLeadRemindingTextFormer); protected readonly UserConnection UserConnection; public UsrLeadRemindingTextFormer(UserConnection userConnection) { UserConnection = userConnection; } // Generates reminder text from a collection of inbound parameters and BodyTemplate localized string. public string GetBody(IDictionary<string, object> formParameters) { formParameters.CheckArgumentNull("formParameters"); var bodyTemplate = UserConnection.GetLocalizableString(ClassName, "BodyTemplate"); var leadName = (string)formParameters["LeadName"]; var body = string.Format(bodyTemplate, leadName); return body; } // Generates reminder title from the class name and TitleTemplate localize string. public string GetTitle(IDictionary<string, object> formParameters) { return UserConnection.GetLocalizableString(ClassName, "TitleTemplate"); } } }
4. Save and publish the schema.
2. Replace the [Lead] object and set the reminder logic in it.
1. Create a replacing schema of the [Lead] object (see “Crating a replacing object schema” section of the “Creating the entity schema” article).
2. Click [Additional] and select [Open process]. Built-in process of the replacing [Lead] object will open (Fig. 3).
Fig. 3. Opening built-in process
3. Using the context menu in the [Structure] tab, add process parameter GenerateReminding (Fig. 4) with the following properties (Fig. 5):
- [Title] – “Generate Reminding”.
- [Name] – "GenerateReminding”.
- [Data type] – “Boolean”.
Fig. 4. Adding a process parameter
Fig. 5. The properties for the process parameter
4. Select the LeadSavingMethod() (called before saving the object) in the [Methods] node on the [Structure] tab (Fig. 6). Select the [Override] checkbox and add the following code to the method body:
// Calling base implementation of the method. base.LeadSavingMethod(); // Getting owner Id. var oldOwnerId = Entity.GetTypedOldColumnValue<Guid>("OwnerId"); // Getting next actualization date. DateTime oldRemindDate = Entity.GetTypedOldColumnValue<DateTime>("NextActualizationDate"); // Comparing Id of original and current owner. bool ownerChanged = !Entity.OwnerId.Equals(oldOwnerId); // Comparing original and current actualization dates. bool remindDateChanged = !Entity.NextActualizationDate.Equals(oldRemindDate); // Set the GenerateReminding process parameter value to "true" if the owner // or actualization date changed. GenerateReminding = ownerChanged || remindDateChanged;
NOTE
To open source code editor of a method, double-click the method name on the [Structure] tab.
Fig. 6. Properties of the LeadSavingMethod
5. Select the LeadSavedMethod() (called after saving the object) in the [Methods] node on the [Structure] tab (Fig. 7). Select the [Override] checkbox and add the following code to the method body:
base.LeadSaved(); // Checks if the reminder must be generated. if (!GenerateReminding) { return; } DateTime remindTime = Entity.NextActualizationDate; if (Entity.OwnerId.Equals(Guid.Empty) || remindTime.Equals(default(DateTime))) { return; } // Instantiates the UsrLeadRemindingTextFormer class. IRemindingTextFormer textFormer = ClassFactory.Get<UsrLeadRemindingTextFormer>(new ConstructorArgument("userConnection", UserConnection)); // Gets lead name. string leadName = Entity.LeadName; // Gets the reminder text. string subjectCaption = textFormer.GetBody(new Dictionary<string, object> { {"LeadName", leadName} }); // Gets reminder title. string popupTitle = textFormer.GetTitle(null); // Configures reminder. var remindingConfig = new RemindingConfig(Entity); // Message author — current contact. remindingConfig.AuthorId = UserConnection.CurrentUser.ContactId; // Target recipient — lead owner. remindingConfig.ContactId = Entity.OwnerId; // Type — reminder. remindingConfig.NotificationTypeId = RemindingConsts.NotificationTypeRemindingId; // Reminder date — next actualization date of an opportunity in lead. remindingConfig.RemindTime = remindTime; // Reminder text. remindingConfig.Description = subjectCaption; // Reminder title. remindingConfig.PopupTitle = popupTitle; // Creating reminder utility class. var remindingUtilities = ClassFactory.Get<RemindingUtilities>(); // Creating reminder. remindingUtilities.CreateReminding(UserConnection, remindingConfig);
Fig. 7. Properties of the LeadSavedMethod
NOTE
To display reminders on the system notification tab , replace remindingConfig.NotificationTypeId = RemindingConsts.NotificationTypeRemindingId; with remindingConfig.NotificationTypeId = RemindingConsts.NotificationTypeNotificationId; in the code of the LeadSavedMethod.
6. Save and publish built-in process schema of the [Lead] object. Publish the [Lead] object schema.
3. Replace the reminder tab schema ReminderNotificationsSchema.
1. To display reminders for a specific object, create a replacing ReminderNotificationsSchema in the custom package and add the needed logic to it. The procedure for creating a replacing client schema is covered in the “Creating a custom client module schema” article. Replacing schema properties (Fig. 8):
- [Title] – “Notifications module”.
- [Name] – “ReminderNotificationsSchema”.
Fig. 8. Properties of the ReminderNotificationsSchema schema
2. Add following source code on the [Source code] tab of the schema:
define("ReminderNotificationsSchema", ["ReminderNotificationsSchemaResources"], function() { return { entitySchemaName: "Reminding", methods: { // Determines of the reminder is related to the lead. getIsLeadNotification: function() { return this.get("SchemaName") === "Lead"; }, // Gets reminder title. getNotificationSubjectCaption: function() { var caption = this.get("Description"); return caption; } }, // Array of view model notifications. diff: [ // Reminder primary container. { "operation": "insert", "name": "NotificationleadItemContainer", "parentName": "Notification", "propertyName": "items", "values": { "itemType": Terrasoft.ViewItemType.CONTAINER, "wrapClass": [ "reminder-notification-item-container" ], // Displays only for leads. "visible": {"bindTo": "getIsLeadNotification"}, "items": [] } }, // Title container. { "operation": "insert", "name": "NotificationItemleadTopContainer", "parentName": "NotificationleadItemContainer", "propertyName": "items", "values": { "itemType": Terrasoft.ViewItemType.CONTAINER, "wrapClass": ["reminder-notification-item-top-container"], "items": [] } }, // Image. { "operation": "insert", "name": "NotificationleadImage", "parentName": "NotificationItemleadTopContainer", "propertyName": "items", "values": { "itemType": Terrasoft.ViewItemType.BUTTON, "className": "Terrasoft.ImageView", "imageSrc": {"bindTo": "getNotificationImage"}, "classes": {"wrapClass": ["reminder-notification-icon-class"]} } }, // Date display. { "operation": "insert", "name": "NotificationDate", "parentName": "NotificationItemleadTopContainer", "propertyName": "items", "values": { "itemType": Terrasoft.ViewItemType.LABEL, "caption": {"bindTo": "getNotificationDate"}, "classes": {"labelClass": ["subject-text-labelClass"]} } }, // Reminder text display. { "operation": "insert", "name": "NotificationleadSubject", "parentName": "NotificationItemleadTopContainer", "propertyName": "items", "values": { "itemType": Terrasoft.ViewItemType.LABEL, "caption": {"bindTo": "getNotificationSubjectCaption"}, "click": {"bindTo": "onNotificationSubjectClick"}, "classes": {"labelClass": ["subject-text-labelClass", "label-link", "label-url"]} } } ] }; });
3. Save the schema.
As a result, bpm’online will create reminders (Fig. 10) for all leads where the owner and actualization date are specified (Fig. 9).
Fig. 9. Lead page where owner and next actualization date fields populated
Fig. 10. Lead custom reminder