Skip to main content
Version: 8.1

Create a custom reminder

Level: intermediate
Example

Create a custom reminder for the opportunity update date in a lead. Creatio displays the date in the Next actualization date field on the Opportunity info tab. Display the reminder on the reminder tab of the notification center.

1. Implement the reminder text and dialog

  1. Go to the Configuration section and select a custom package to add the schema.

  2. Click AddSource code on the section list toolbar.

  3. Fill out the schema properties in the Source Code Designer:

    • Set Code to "UsrLeadRemindingText."
    • Set Title to "Lead reminding text."

    Click Apply to apply the properties.

  4. Add a localizable string that contains the reminder dialog caption.

    1. Click the button in the context menu of the Localizable strings node.

    2. Fill out the localizable string properties:

      • Set Code to "TitleTemplate."
      • Set Value to "You need to update the sale."
    3. Click Add to add a localizable string.

  5. Add a localizable string that contains the reminder text similarly.

    View the properties of the localizable string to add in the table below.

    Localizable string properties

    Code

    Value

    "BodyTemplate"

    "Lead 0 requires update of sales information"

  6. Implement the reminder text and dialog.

    View the source code of the source code schema below.

    UsrLeadRemindingText
    namespace Terrasoft.Configuration
    {
    using System.Collections.Generic;
    using Terrasoft.Common;
    using Terrasoft.Core;

    public class UsrLeadRemindingText : IRemindingTextFormer
    {
    private const string ClassName = nameof(UsrLeadRemindingText);
    protected readonly UserConnection UserConnection;

    public UsrLeadRemindingText(UserConnection userConnection) {
    UserConnection = userConnection;
    }
    /* Generate the reminder text using the collection of incoming parameters and BodyTemplate localizable 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;
    }
    /* Generate the reminder caption using the class name and TitleTemplate localizable string. */
    public string GetTitle(IDictionary<string, object> formParameters) {
    return UserConnection.GetLocalizableString(ClassName, "TitleTemplate");
    }
    }
    }
  7. Click Save on the Source Code Designer's toolbar to save the changes to Creatio properties temporarily.

  8. Click Publish on the Source Code Designer's toolbar to apply the changes to the database level.

2. Implement the mechanism that sends the reminder

  1. Go to the Configuration section and select a custom package to add the schema.

  2. Click AddReplacing object on the section list toolbar.

  3. Select "Lead" in the Parent object property of the Object Designer.

  4. Create an object event.

    1. Open the Events node.
    2. Go to the Adding block → select the After record added checkbox.
  5. Set up the parameter the business process uses to generate the reminder in the object schema.

    1. Click Save on the Object Designer's toolbar.

    2. Click Open process on the Object Designer's toolbar.

    3. Add a parameter.

      1. Open the Parameters tab in the setup area and click Add parameterBoolean.

      2. Fill out the parameter properties in the Object Designer.

        • Set Title to "Generate reminding."
        • Set Code to "GenerateReminding."
      3. Click Save.

    4. Overload the methods.

      • Overload the method called after the object is saved. To do this, open the Methods tab of the setup area and add the source code of the overloaded LeadSaved() method.

        LeadSaved()
        public override void LeadSaved() {
        base.LeadSaved();
        /* Check whether the reminder must be generated. */
        if (!GenerateReminding) {
        return;
        }
        DateTime remindTime = Entity.NextActualizationDate;
        if (Entity.OwnerId.Equals(Guid.Empty) || remindTime.Equals(default(DateTime))) {
        return;
        }
        /* Create an instance of the UsrLeadRemindingText class. */
        IRemindingTextFormer textFormer = ClassFactory.Get<UsrLeadRemindingText>(new ConstructorArgument("userConnection", UserConnection));
        /* Retrieve the lead name. */
        string leadName = Entity.LeadName;
        /* Retrieve the reminder text. */
        string subjectCaption = textFormer.GetBody(new Dictionary<string, object> {
        {"LeadName", leadName}
        });
        /* Retrieve the reminder caption. */
        string popupTitle = textFormer.GetTitle(null);
        /* Configure the reminder. */
        var remindingConfig = new RemindingConfig(Entity);
        /* Set the message author to the current contact. */
        remindingConfig.AuthorId = UserConnection.CurrentUser.ContactId;
        /* Set the target recipient to the lead owner. */
        remindingConfig.ContactId = Entity.OwnerId;
        /* Set the type to reminding. */
        remindingConfig.NotificationTypeId = RemindingConsts.NotificationTypeRemindingId;
        /* Set the date for sending a reminder to the opportunity update date in the lead. */
        remindingConfig.RemindTime = remindTime;
        /* Reminder text. */
        remindingConfig.Description = subjectCaption;
        /* Reminder caption. */
        remindingConfig.PopupTitle = popupTitle;
        /* Create a utility class of the reminder. */
        var remindingUtilities = ClassFactory.Get<RemindingUtilities>();
        /* Create a reminder. */
        remindingUtilities.CreateReminding(UserConnection, remindingConfig);
        }

        The RemindingConsts.NotificationTypeRemindingId value of the remindingConfig.NotificationTypeId constant lets you display the notification on the reminder tab of the notification center. If you set the constant to RemindingConsts.NotificationTypeNotificationId, Creatio displays the reminder on the service message tab of the notification center.

      • Overload the method called before the object is saved. To do this, open the Methods tab and add the source code of the overloaded LeadSavingMethod() method.

        LeadSavingMethod()
        public override void LeadSavingMethod() {
        /* Call the base method implementation. */
        base.LeadSavingMethod();
        /* Retrieve the owner ID. */
        var oldOwnerId = Entity.GetTypedOldColumnValue<Guid>("OwnerId");
        /* Retrieve the date of the next update. */
        DateTime oldRemindDate = Entity.GetTypedOldColumnValue<DateTime>("NextActualizationDate");
        /* Compare the old and new owner IDs. */
        bool ownerChanged = !Entity.OwnerId.Equals(oldOwnerId);
        /* Compare the old and new update dates. */
        bool remindDateChanged = !Entity.NextActualizationDate.Equals(oldRemindDate);
        /* Set the GenerateReminding process parameter to true if the owner or date of the next update changed. */
        GenerateReminding = ownerChanged || remindDateChanged;
        }
    5. Click Save then Publish on the Object Designer's toolbar.

    6. Click Cancel on the Object Designer's toolbar.

  6. Click Publish to create a corresponding database table.

3. Implement the mechanism that displays the reminder

  1. Go to the Configuration section and select a custom package to add the schema.

  2. Click AddReplacing view model on the section list toolbar.

  3. Select "ReminderNotificationsSchema" in the Parent object schema property of the Module Designer.

    Click Apply to apply the properties.

  4. Implement the mechanism that displays the reminder.

    1. Implement the following methods in the methods property:

      • getIsLeadNotification(). Determines whether the reminder is connected to the lead.
      • getNotificationSubjectCaption(). Returns the reminder caption.
    2. Add configuration objects with the settings that determine layouts of the following elements to the diff array of modifications:

      • container on the page
      • caption container
      • image
      • date
      • reminder text

    View the source code of the replacing view model schema below.

    ReminderNotificationsSchema
    define("ReminderNotificationsSchema", ["ReminderNotificationsSchemaResources"], function() {
    return {
    /* The name of the object schema. */
    entitySchemaName: "Reminding",
    /* The methods of the view model. */
    methods: {
    /* Determine whether the reminder is connected to the lead. */
    getIsLeadNotification: function() {
    return this.get("SchemaName") === "Lead";
    },
    /* Return the reminder caption. */
    getNotificationSubjectCaption: function() {
    var caption = this.get("Description");
    return caption;
    }
    },
    /* Display the reminder. */
    diff: [
    /* The properties to add the container. */
    {
    /* Add the element to the page. */
    "operation": "insert",
    /* The meta name of the container to add. */
    "name": "NotificationleadItemContainer",
    /* The meta name of the parent container to add the current container. */
    "parentName": "Notification",
    /* Add the container to the parent element's collection of elements. */
    "propertyName": "items",
    /* The properties to pass to the element's constructor. */
    "values": {
    "itemType": Terrasoft.ViewItemType.CONTAINER,
    "wrapClass": [
    "reminder-notification-item-container"
    ],
    /* Display only for leads. */
    "visible": {"bindTo": "getIsLeadNotification"},
    "items": []
    }
    },
    /* The properties to add the caption container. */
    {
    "operation": "insert",
    "name": "NotificationItemleadTopContainer",
    "parentName": "NotificationleadItemContainer",
    "propertyName": "items",
    "values": {
    "itemType": Terrasoft.ViewItemType.CONTAINER,
    "wrapClass": ["reminder-notification-item-top-container"],
    "items": []
    }
    },
    /* The properties to add the 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"]}
    }
    },
    /* The properties for the date. */
    {
    "operation": "insert",
    "name": "NotificationDate",
    "parentName": "NotificationItemleadTopContainer",
    "propertyName": "items",
    "values": {
    "itemType": Terrasoft.ViewItemType.LABEL,
    "caption": {"bindTo": "getNotificationDate"},
    "classes": {"labelClass": ["subject-text-labelClass"]}
    }
    },
    /* The properties for the reminder text. */
    {
    "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"]}
    }
    }
    ]
    };
    });
  5. Click Save on the Module Designer's toolbar.

Outcome of the example

To view the outcome of the example:

  1. Refresh the Leads section page.
  2. Open the lead page → the Opportunity info tab.
  3. Select the needed date and time of the opportunity update in the Next actualization date field.
  4. Select your user contact in the Owner field.

As a result, Creatio will display the reminder for the opportunity update date in the lead on the reminder tab of the notification center.

Source codes

Lead_sdkSendCustomNotificationPackageEventsProcess
namespace Terrasoft.Configuration
{

using DataContract = Terrasoft.Nui.ServiceModel.DataContract;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Web;
using Terrasoft.Common;
using Terrasoft.Common.Json;
using Terrasoft.Configuration.PRM;
using Terrasoft.Core;
using Terrasoft.Core.Configuration;
using Terrasoft.Core.DB;
using Terrasoft.Core.DcmProcess;
using Terrasoft.Core.Entities;
using Terrasoft.Core.Factories;
using Terrasoft.Core.Process;
using Terrasoft.Core.Process.Configuration;
using Terrasoft.GlobalSearch.Indexing;
using Terrasoft.UI.WebControls.Controls;
using Terrasoft.UI.WebControls.Utilities.Json.Converters;

#region Class: Lead_sdkSendCustomNotificationPackageEventsProcess

public partial class Lead_sdkSendCustomNotificationPackageEventsProcess<TEntity>
{

#region Methods: Public

public override void LeadSaved() {
base.LeadSaved();
/* Check whether the reminder must be generated. */
if (!GenerateReminding) {
return;
}
DateTime remindTime = Entity.NextActualizationDate;
if (Entity.OwnerId.Equals(Guid.Empty) || remindTime.Equals(default(DateTime))) {
return;
}
/* Create an instance of the UsrLeadRemindingText class. */
IRemindingTextFormer textFormer = ClassFactory.Get<UsrLeadRemindingText>(new ConstructorArgument("userConnection", UserConnection));
/* Retrieve the lead name. */
string leadName = Entity.LeadName;
/* Retrieve the reminder text. */
string subjectCaption = textFormer.GetBody(new Dictionary<string, object> {
{"LeadName", leadName}
});
/* Retrieve the reminder caption. */
string popupTitle = textFormer.GetTitle(null);
/* Configure the reminder. */
var remindingConfig = new RemindingConfig(Entity);
/* Set the message author to the current contact. */
remindingConfig.AuthorId = UserConnection.CurrentUser.ContactId;
/* Set the target recipient to the lead owner. */
remindingConfig.ContactId = Entity.OwnerId;
/* Set the type to reminding. */
remindingConfig.NotificationTypeId = RemindingConsts.NotificationTypeRemindingId;
/* Set the date for sending a reminder to the opportunity update date in the lead. */
remindingConfig.RemindTime = remindTime;
/* The reminder text. */
remindingConfig.Description = subjectCaption;
/* The reminder caption. */
remindingConfig.PopupTitle = popupTitle;
/* Create a utility class of the reminder. */
var remindingUtilities = ClassFactory.Get<RemindingUtilities>();
/* Create a reminder. */
remindingUtilities.CreateReminding(UserConnection, remindingConfig);
}

public override void LeadSavingMethod() {
/* Call the base method implementation. */
base.LeadSavingMethod();
/* Retrieve the owner ID. */
var oldOwnerId = Entity.GetTypedOldColumnValue<Guid>("OwnerId");
/* Retrieve the date of the next update. */
DateTime oldRemindDate = Entity.GetTypedOldColumnValue<DateTime>("NextActualizationDate");
/* Compare the old and new owner IDs. */
bool ownerChanged = !Entity.OwnerId.Equals(oldOwnerId);
/* Compare the old and new dates of the update. */
bool remindDateChanged = !Entity.NextActualizationDate.Equals(oldRemindDate);
/* Set the GenerateReminding process parameter to true if the owner or date of the next update changed. */
GenerateReminding = ownerChanged || remindDateChanged;
}
#endregion

}

#endregion

}

Resources

Package with example implementation