In Flexie CRM, a core part of it, is the Templates section, which you can use to create reusable content for your emails, notes and everything else related to content you distribute or generic use within your CRM.

Templates have the capability to parse the Flexie Scripting language, which is a very handy tool to compose highly dynamic content. In the Templates section there are 2 type of templates, the Note Template, and the Email Template, both of them have the same capabilities in terms of content parsing and handling.

A very important part of Email and Note templates are the Snippets, which is a small reusable part of content, which may be included in both email and note templates. Snippets are very useful for organizing your template content, because you might have small pieces of information used everywhere so you won’t want to duplicate your content and moreover you won’t want to do changes in all templates if something small has the need to be changed. For instance your signature, you have it in almost any template, so you can add a snippet for handling your signature only, which might be used in 100+ templates… See, how handy and practical it is?

Here it comes the scripting needs… imagine what’s a CRM all about if everything could not be dynamic! So with that being said, the scripting is a must in the nowadays.

We will explain the Scripting by parts, so first part is the capability you have to parse dynamic variables in your templates. What does this mean?

Dynamic variables are data records from your entities you use to write personalized emails or dynamic notes and a lot more, but lets take the email example. When you create a new Email Template you are asked to choose the entity this email template belongs to, so let say you would choose Leads. This mean that, any lead you going to send this email template, you can parse lead data within the template.

Hey {{first_name}},

there was a pleasure to talk to you today
. . .

Kind Regards,
{{owner_id.first_name}}

So notice this sample email template, the parts within {{ and }} are the dynamic variables, in this case the first_name is the lead field with the alias as first_name, so the parsed wordings would be “Hey Marc, … ” because the word Marc, is on that record you are sending the email.

Within the template, you can parse dynamic variables, use IF/ELSE statements, call built-in methods or include snippets.

How all this can be done? Well, we gone get one by one illustrated with real cases examples, without doing boring theoretical explanation.

Parsing and Setting a Variable

A variable is always parsed using {{ … }}, so double bracket, but you can also set a variable and do manipulation on it.

//Parse a variable
Hello {{first_name}} {{last_name}} ...

//Set a variable
{% set randomGreeting = random(['Hello', 'Hi', 'Hey, how are you', 'Dear']) %}

//Then you can use the already set variable
{{randomGreeting}} {{first_name}}

//The above would output random greeting
Hello Marc OR Hi Marc OR Hey, how are you Marc

Notice above that we used the random method, which is a build-in method and returns a random value. So it gets as an argument a collection of values, which can be static words like in the example or variables, but in the variable case the single quote is not needed.

Using IF/ELSE statements

You can use conditional statements within your template, so you can create conditional values for any scenario.

Hello {{first_name}},
{% if status == 'New' %}
we would like to invite you to our ...
{% else %}
we would like to have a feedback from you in regard to ...
{% endif %}

...

Thank you,
{{owner_id.first_name}}

As you can see the IF/ESLE statement its pretty straightforward and simple to understand, also the “status” word in there, refers to a variable, and its exactly the status field of the entity, and what the block of this statement does, it checks if the status of the Lead is New, then it parse a different message based on that condition.

Looping through records

Let say you have the contacts entity, which has a children entity of subscribed events, so you may want to email them and remind about all upcoming events, so what you may need to do is to use the built-in method findMany, and filter the subscribed events belonging to the contact you are emailing. In this way you can loop through those records.

Hello {{first_name}} {{last_name}},

we would like to remind you about these upcoming events:

{% set getContactEvents = findMany('subscribed_events', 'contacts_id', id) %}
{% for event in getContactEvents %}
{{event.name}} starts at {{event.start_at}}
{% endfor %}

...

We would like your confirmation for these events, 

Thanks in Advance,
{{owner_id.first_name}}

It’s pretty clear and self explanatory, we get all events which belongs to the contact, loop through them and parse the fields we are interested in, this way we are creating a template by parsing dynamic variables, getting additional data, looping through them, and also parsing dynamic variables within the loop itself.

The built-in methods

In Flexie CRM, there are some pre-built methods which can be used, and cover almost any scenario you may have. We will list here for you reference so you can tell which one does what.

//Date manipulation method
date(‘date string’, ‘format’, ‘To Timezone’, ‘From Timezone’)

//Mathematical Add method
add(‘number’, ‘number’, ‘number’ …)

//Mathematical Subtract method
subtract(‘number’, ‘number’)

//Mathematical Multiply method
multiply(‘number’, ‘number’, ‘number’ …)

//Mathematical Divide method
divide(‘number’, ‘number’)

//Mathematical Square Root method
squareRoot(‘number’)

//Mathematical Cube Root method
cubeRoot(‘number’)

//Round a number function
//mode argument options "ROUND_HALF_UP", "ROUND_HALF_DOWN", "ROUND_HALF_EVEN", "ROUND_HALF_ODD"
round(‘number’, ‘precision’, ‘mode’)

//Find One Record on a specific entity
findOne(‘entity’, ‘field alias’, ‘value’)

//Find Many Records on a specific entity
//Order Direction argument options "ASC", "DESC"
findMany(‘entity’, ‘field alias’, ‘value’, ‘order by field alias’, ‘order direction’, ‘limit’)

//Count records on a specific entity ex. Leads
//Min arguments are Entity, Entity Field, Entity Value.
//You can enter as many Field Alias - Field Values pair as you want.
//Example: findCount('lead', 'status', 'new', 'source', 'website')
findCount(‘entity’, ‘field alias’, ‘field value’, ‘field alias’, ‘field value’……)

//Find all Deals for a specific entity id.
//Example: findDeals('lead', '1111') will fetch all deals for lead id 1111.
findDeals(‘entity’, ‘entity id’)

//Find Deals Value for a specific entity id.
//Example: findDealsValue('lead','won','sales','1111') will calculate deals value on stage 'won' and pipeline 'sales' for lead id 1111.
findDealsValue(‘entity’, ‘stage’, ‘pipeline’, ‘entity id’)

//Find all Cases for a specific entity id.
//Example: findCases('contact', '2222') will fetch all cases for contact id 2222.
findCases(‘entity’, ‘entity id’)

//Get Smart List Records
getSmartListRecords(‘entity’, ‘smart list alias’)

//Generate a Short Link at the runtime within the email templates
//First argument is the long URL you want to shorten
//Second argument is the entity and the third is the current ID
//The entity and id parameters are used from the short link service
//to call Flexie CRM back if someone goes to that short link, basically
//when someone clicks on the short link.
getShortLink(‘https://mydomain.com?leadId=455’, ‘lead’, 455)

//Get the Smart Link URL from the Smart Link menu. This method could also generate
//a short link based on the smart link URL, very handy when you want to put some nice
//and short links in email. First argument is the alias of the smart link,
//Second argument is the entity of the smart link, like lead, contact, account, or any custom entity you might have, (note: default entities does not have the plural 's' instead all the other custom entities must have the plural 's')
//Third argument is the ID of the entity,
//and the fourth argument it's either to create or not the short link
//Short link generation it's by default false, so you have explicitly set it to true
//if you want that to be a short link.
getSmartLink(‘smart_link_alias’, ‘entity’, ‘entityId’, true/false)

//Minimum number of arguments for this method is two.
//The first argument is the number to be formatted
//and the second is the number of digits after the decimal point
numberFormat(number, decimals)

//Transform any parameter in URL ENCODED, useful when having links with dynamic parameters
//and you have values which needs to be encoded
urlEncode(‘url param’)

//Encodes the given string data with base64
base64encode(‘string’)

//This method decodes Base64-encoded value into the original string.
base64decode(‘base64value’)

//Transform any string or set of characters into alphanumeric comprising only numbers and lowercase letters
toAlphaNumeric(‘value’)

//Add a new tag and preserves the previously set ones.
//First argument is the Field Name holding tags, and the second argument is the new tag value
addTag(tags, ‘newTagValue’)

//Removes a tag and preserves the other tags if there are any.
//First argument is the Field Name holding tags, and the second argument is the tag to be removed
removeTag(tags, ‘tagToRemove’)

//Displays all the attachments of the entity with an specific i if there are any.
addAttachments(‘entity name’, ‘entity id’)

//Extract email addresses from a given text.
extractEmails(text)

//Extract phone numbers from a given text.
extractPhoneNumbers(text)

//Extract links from a given text.
extractWebsiteLinks(text)

//MD5 hash method
md5(‘value’)

//Dump method for debugging variable values
dump(‘anything’)

To stay updated with the latest features, news and how-to articles and videos, please join our group on Facebook, Flexie CRM Academy.