Author: 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 practising 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:
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:
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:
In Template section compose the message, insert variables into text (click Play button near the variable, add some formatting (using TinyMCE functions or HTML):
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:
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 🙂
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:
Select Email fields in Get Entity Attributes and link it with Structure Fields:
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:
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:
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):
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:
Then we need to fill data in our structure with a file from Note. Get filename from Note and set into the structure:
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:
Specify decorator details – module Notes, id from Note and field – Attachment:
Finally, add the attachment to the collection:
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:
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.
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:
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:
Then specify Object module for this record, which is an Email and Object Id which is an email ID:
Fill Event type ID with ID of Timeline Event entity, which we found by Name before:
Fill Context with the structure, which we created:
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:
Fill parameters in the template with the data from the Email entity:
Lastly, save the new record:
Save the flowchart, deploy it on SugarCRM instance.
After deploying, the event may look like this: