How to Create an Event for a Sent or Received Email in SugarCRM

SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received EmailAuthor: Anastasiia Gubanovych, CRM Consultant

In this SugarCRM tutorial, we are going to consider an example on how to create an event for a sent or received Email in Timeline Viewer using Logic Builder.

For practicing this SugarCRM tutorial, you need:

• SugarCRM instance with installed Timeline Viewer and LB Templates

• Access to Logic Builder https://logicbuilder.integroscrm.com/.

Let’s assume that we want to chronicle every email to or from Contact into Timeline.

Step 1: Create Timeline Event

First things first – create a new type of the event in SugarCRM. Navigate to the Timeline Events module and create a new record:
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email
Fill in a new record with data:

  • Name – enter a name of the event, like ‘Contact. Email was created’.
  • Icon – find (or create) an icon, which suits best this type of the event.
  • Target module – we are creating an event for Contacts, that’s why Contact is our target module.
  • Lifetime Units, Lifetime Duration – leave as is, if one year is more than enough for email creation event being in the system for the particular record. Change these values if you need historical data to be stored longer.
  • You may add a Description to the event (optionally)

Save the record when you finish.

>

Step 2: Create a fancy message

Besides a nice-looking image for the event, there should be an informative and readable message. Create one in LB Templates module – navigate there and create a new record:
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email
Fill the name of the template, so that its purpose is clear.

Then think about the message, which users will see in SugarCRM. It’s most likely that we must define the subject of the message, who sent and to whom. This is data from a particular email, thus we have variables here. Define them in Context section:
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email
In Template section compose the message, insert variables into text (click Play button near the variable, add some formatting (using TinyMCE functions or HTML):
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email
Click Save when you finish.

Step 3: Build a flowchart for events’ generating

Move to Logic Builder, log in and import metadata from SugarCRM, where you’ve just created the event and the template.

Chose operator On Link Change, where specify target module Emails, subject module Contacts, link Emails:Contacts (contacts) and event type After Relationship Add:
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email
Do we have any conditions here? No, we don’t. Right away proceed to Create Context for the event. Unlike in the example of creating an event for the Call, you do not have many options here: either you create a custom context (so that users will have Preview of an Email in the interface), or leave it empty (users won’t have any Preview). We want to deliver a convenient solution for users, so let’s build custom context. You can define the information, which is displayed on Preview via structure operators in Logic Builder. You create structure, define the fields which the structure will comprise (and these fields will be displayed on Preview). Then you put data from SugarCRM record into structure fields. You can simply format structure fields by using decorators as a bonus.

Firstly, create the structure and define fields, which are going to be as detailed information for an email. Let it be an email subject, from who and to whom, cc of email, attachments, email body and date of the sent email. If you need other order or other information – feel free to modify it 🙂
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email
It is not enough just to define the fields, usually, we need to put some information in it. We can set information in the structure by using Set Structure Fields. Some of the data we can get from the email, which is Object module, so Get Entity Attributes from Email:
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email
Select Email fields in Get Entity Attributes and link it with Structure Fields:
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email
Now we need to do some trick. A body in the email is html-formatted, so in order the text to be well displayed in SugarCRM for users we need to add HTML formatting to value in this field. For adding decorators to the structure field use Apply Field Decorator operator, where put the structure in an input, select the field which needs to be formatted (body) and specify the decorator – here we need simple HTML Decorator:
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email
Have you noticed that we didn’t fill attachments field? Because an attachment is not data in one field, it is data from Notes, that are related to Email and where attachments are stored. That is why now we are going to retrieve Notes related to Email, and collect Attachments. Also, we need to create a collection, where attachments will be stored to further output in Preview:
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email
To retrieve Notes from Emails, we use Retrieve Related Entities operator, where we put an email entity on input and use the link Emails:Notes (notes):
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email
Then to add every related attachment to Email into Preview section we go through every Note, so put For Each Entity operator. For every attachment, we need to create Structure. All we need to output in the Preview is attachment name, so define only one field in the structure:
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email
Then we need to fill data in our structure with a file from Note. Get filename from Note and set into the structure:
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email
One more thing we need to do in our SugarCRM tutorial before adding the structure into the collection – apply the attach decorator to the structure field so that users can download the file directly from the Preview. To add formatting to the structure field use operator Apply Field Decorator, where specify the structure and select the structure field to which the decorator will be applied. Then find the decorator – currently we need Attach Decorator:
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email
Specify decorator details – module Notes, id from Note and field – Attachment:
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email
Finally, add the attachment to the collection:
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email
That is all about a cycle, so now we can set the last field in the structure and proceed to create the event for the Contact.

Set Attachments field in the structure with the collection:
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email
To create the event we need to specify Timeline Event, to which this event will be related. We are going to find the Timeline Event by Name (you may use any other unique attributes to find Timeline Event). Continue the control flow from the completed part in For Each Entity and put Retrieve Entities By Attributes. As mentioned, we are looking for Timeline Event entity with name ‘Contact. Email was created’ (which we created in step 1).

Note: make sure that you have one and only one Timeline Event entity with such name. If there is more than one – precise searching fields by adding Target Module, for example.
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email
Now we have all data from the event so that we can create it. Put operator Create Entity and select Timeline in it. Then put Set Entity Attributes, as we need to define data into the new event:
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email
Set fields. First, identify the record to which this event is registered. For this, fields Target Module and Parent ID in Timeline are responsible. Fill them with Contacts module and Contact ID:
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email
Then specify Object module for this record, which is an Email and Object Id which is an email ID:
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email
Fill Event type ID with ID of Timeline Event entity, which we found by Name before:
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email
Fill Context with the structure, which we created:
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email
Last field that we need to fill is the message, which is called Rich-text message. In this field, we put the result of processing template, which we created in step 2. Use Get HTML Text From Template and select the template:
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email
Fill parameters in the template with the data from the Email entity:
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email
Lastly, save the new record:
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email
Save the flowchart, deploy it on SugarCRM instance.

After deploying, the event may look like this:
SugarCRM Tutorial: How to Create Timeline Viewer Event for a Sent or Received Email

WEBINAR: A Smart Way to Collect Key Business Events in SugarCRM for BI and AI

Leave a Reply

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