Skip to main content
Version: 8.0

Implement email template using custom macro

Level: advanced

To implement the example:

  1. Implement a custom macro. Read more >>>
  2. Register the custom macro in the database. Read more >>>
  3. Set up the email template. Read more >>>
Example

Implement the custom "Notification. New documentation release" email template. The email template must include the following text:

Greetings!

I hope you're doing well.

At Creatio, we are committed to empowering our customers with industry-leading product innovations for workflow automation, no-code app development, and CRM. We are introducing updated documentation. You can access the documentation here: Creatio documentation.

Best regards,

Creatio

Use a custom macro to display the company name.

1. Implement a custom macro

  1. Open the Configuration section. Instructions: Open the Configuration section.

  2. Create a package. Instructions: Create a user-made package.

    For this example, create the sdkAddCustomEmailMacro package.

  3. Create the source code schema. To do this, click AddSource code.

  4. Fill out the schema properties.

    For this example, use the schema properties as follows.

    Property

    Property value

    Code

    UsrCompanyName

    Title

    CompanyName

  5. Apply the changes.

  6. Implement the business logic of the email macro.

    UsrCompanyName
    namespace Terrasoft.Configuration
    {
    using System;
    using Terrasoft.Core;

    /* Class that implements the "IMacrosInvokable" interface. */
    public class UsrCompanyName : IMacrosInvokable
    {

    /* A user connection. */
    public UserConnection UserConnection
    {
    get;
    set;
    }

    /* Implement the "GetMacrosValue()" method of the "IMacrosInvokable" interface. */
    public string GetMacrosValue(object arguments)
    {

    /* Method that returns string value for macros. */
    return "Creatio";

    }
    }
    }
  7. Publish the schema.

2. Register the custom macro in the database

To do this, execute the SQL query to the EmailTemplateMacros database table that stores the email templates.

SQL query
INSERT INTO EmailTemplateMacros(Name, Parentid, ColumnPath)
VALUES (
'UsrCompanyName',
(SELECT TOP 1 Id
FROM EmailTemplateMacros
WHERE Name = '@Invoke'),
'Terrasoft.Configuration.UsrCompanyName'
)

3. Set up the email template

  1. Open the Message templates section in Creatio.

  2. Create a custom email template.

    1. Click NewEmail template.

    2. Fill out the properties of the email template.

      Property

      Property value

      Template name

      Notification. New documentation release

      Subject

      New documentation release

      Email template

      1. Click Edit.
      2. Set up the content of the email template. Instructions: Work with message templates (user documentation).
      3. Replace the "Creatio" company name using [#@Invoke.UsrCompanyName#] macro.
      4. Save the changes.

As a result, the custom "Notification. New documentation release" email template will be as follows.

View the result

  1. Open the Communication panel.

  2. Open the Emails panel.

  3. Click . This opens the New Email window.

  4. Insert the email template.

    1. Click . This opens the Select: Message template window.
    2. Select the "Notification. New documentation release" email template.
    3. Click Select.

As a result, the email will include the custom "Notification. New documentation release" email template. The company name will be replaced by custom macro value. View the result >>>

Source code

namespace Terrasoft.Configuration
{
using System;
using Terrasoft.Core;

/* Class that implements the "IMacrosInvokable" interface. */
public class UsrCompanyName : IMacrosInvokable
{

/* A user connection. */
public UserConnection UserConnection
{
get;
set;
}

/* Implement the "GetMacrosValue()" method of the "IMacrosInvokable" interface. */
public string GetMacrosValue(object arguments)
{

/* Method that returns string value for macros. */
return "Creatio";

}
}
}

Resources

Package with example implementation