Set Up Automated Emails on SLA Events
In this guide, we will configure the Incident type of request to send emails on SLA events. We will do this using automated actions.
We have 2 configured SLA Rules: Reaction Time and Resolve Time. The task is to set up actions to automatically send emails when SLA reaches its warning and limit.
On the Reaction Time SLA Rule (until request is assigned), an email on the SLA Warning should be sent to all members of the Frontend Team. When the Rosolve Time SLA Rule is active (after request is assigned), an SLA Warning email must be sent to the assigned person.
An email about failed SLA on the Reaction Time Rule, should be sent to the Team leader; and on the Resolve Time Rule, it should be sent to the manager of the assigned person.
Let's quickly review the Frontend Team configuration
Using our Generic Team addon, we previously created the Frontend team. It is a simple team with a team leader and 2 team members.
For more info on how to create a team, read the Documentation.
Configure Event Conditions
We also need to create 2 custom conditions. These conditions will help to determine the active SLA Rule at the present time.
Created conditions will check if the related field "SLA Rule type" contains the Assigned (or Unassigned) value.
We can create conditions from the Rules -> Generic Conditions menu, or we can do this directly from the action form when we select the event conditions.
SLA Rule type - Assigned:
SLA Rule type - Unassigned:
More info about creating generic conditions you can read in the Documentation.
Setting Up Automated Actions
Open the Incident type of request in the edit mode. Click Actions on the form.
Click Create to create a new action.
First, we will create conditions for the Resolve Time SLA Rule.
Automated Action: send email on SLA Warning to the assigned person
This action will be activate on the Resolve Time SLA Rule and will send an email to the assigned person.
The configuration will be as follows:
- Enter the name of the Action.
- This action should send emails on SLA Warning. Select Event: SLA Warning.
- Select the Event condition: SLA Rule type - Assigned. This action is configured for the Resolve Time SLA Rule (when request is assigned).
- Type of action - Send Email.
- On the Send Email tab, we need to select or create an email template for this email. There is no default email templates for our needs, so wee will create a new one.
Odoo Email Templates
Email template allows to specify content of the email, email address of the sender, recipients, copy recipients, preferred response addresses, translation language, outgoing mail server, even schedule send date, etc.
Most all of the template fields may use Jinja2 (Maco compatible) placeholders. They allow to use template language for programming some logic and get values from models and fields.
The template expression should be in curly brackets and it must be preceded by the "$" sign.
Let's create a template with a simple content that will be sent to the assigned person.
In the upper fields, we need to enter the template name: SLA Warning notification (Resolve Time), and specify the type of document this template can be used with. We select Request.
The Content tab configuration
-
Subject
SLA Warning: ${object.display_name}
"object" represents the current request
"object.display_name" - will display the name of request
-
Email text
object.user_id.name or ''
- will insert the name of the assigned person ("user_id.name") or an empty character (''), if there is no assigned user. "object.sudo().type_id.display_name" - will display the name of the request type. We use "sudo()" to pass the security restrictions and get the request type name. "object.name" - will display the request name. We can use the request name as a link to allow the assigned person to open this request from the mail body. We can do the following:-
select the text and click the Link icon, or press Ctrl + K.
-
In the URL or Email field, specify the method of the Request model that gets request link.
-
Now we can make Email Configuration
On this tab, we can specify the sender address. This will be the user company's address.
${(user.company_id.email and '"%s"
This line will place user company name and email to the sender field. "|safe" - is a filter to prevent automatic escaping of this value.
Recipient should be the assigned user. We can configure this using either 1) To (Emails) field - there we need to enter the required email address ("object.user_id.email"), or 2) To (Partners) field - we can specify the partner id in this field ("object.user_id.partner_id.id").
Advanced Settings
On this tab, we can specify the translation language of the email. It should be the language of the assigned user ("object.user_id.lang").
The Dynamic Placeholder Generator tab allows to generate placeholder expression to use in the email template. It can be very helpful. You just need to select the required field / sub-field of the model and specify the default value if necessary.
Now email template is complete and we can save the action.
And here is an example of the set up email, that is sent using our configuration.
Automated Action: send email on SLA Failed to the manager of the assigned person
This action will send emails to the manager of the assigned person in case of SLA fails. It will have the similar configuration, with a few differences.
The Event to trigger the action will be SLA Failed.
The Event Condition will also be the same: SLA Rule type - Assigned.
And we need to create a new email template to send the email to the manager of the assigned user.
In the email template, we need to specify HR related fields. We can use our Bureaucrat HR (user) addon to do this more conveniently.
Bureaucrat HR (user) Addon
Bureaucrat HR (user) is a technical addon. It extends the standard user model by adding additional HR-related fields. These fields are employee_id, hr_job_id, hr_department_id, hr_manager_id, hr_coach_id.
With this addon, we can use hr_manager_id field form the user model to specify the manager of the assigned user.
Now we can set up email template to send emails to the manager in case of SLA failure.
Content tab
-
Subject
SLA Failed: ${object.display_name}
-
Email text
Dear ${object.user_id.hr_manager_id.name or ''}, ${object.sudo().type_id.display_name} ${object.name} assigned to ${object.user_id.name} has Failed the SLA.
Here, we use "object.user_id.hr_manager_id.name" to display the name of the manager. Other placeholders are set as in the previous example. "${object.name}" is also used as a link to open the request from the email.
Email Configuration
We set the sender address as in the previous template.
Let's send this email to the Working Email Address of the manager. In the To (Emails) field, write the following:
${object.user_id.hr_manager_id.work_email}
Advanced Settings
We also specify the translation language of the manager for this email.
We can now save the template and the action.
And here is an email example sent to the manager of the Demo User that failed the SLA.
Now, we will create 2 actions for the Reaction Time SLA Rule, when a request has not been assigned yet.
Automated Action: send email on SLA Warning to all Team members
The action form will have the following configuration:
-
Events: SLA Warning.
-
Event Conditions: SLA Rule type - Unassigned.
- Type: Send Email.
And we need to create a template to send emails to all team members of the Frontend Team.
Content Tab
-
Subject
SLA Warning: ${object.display_name}
-
Email Text
Unassigned ${object.sudo().type_id.display_name} ${object.name} has reached the SLA Warning.
Email Configuration
-
From
${(user.company_id.email and '"%s"
-
To (Partners). This field expects comma-separated ids of recipient partners (as a string). We need to write the following code to get team member ids of the Frontend team.
${ ','.join(map(str, user.env['generic.team'].search([('name', '=', 'Frontend team')], limit=1).team_member_ids.mapped('user_id.partner_id.id'))) }
Some descriptions:
-
user.env['generic.team'].search([('name', '=', 'Frontend team')], limit=1)
This part of code finds team object with the name "Frontend team".
-
.team_member_ids.mapped('user_id.partner_id.id')
Gets team member ids from that team object; then gets each team member user id; and then gets partner id of these users from the partner model.
-
map(str, ...)
Python built-in map() function, which in our case converts resulting ids into a string.
-
','.join(...)
Python str.join() function, in our case it separates result with commas
-
In multilingual companies, where the team name can be translated, this part of code may cause errors.
In that case, better not to use the search by team name, but use team id instead.
To get the required team id, you can open the team form. The id may be obtained from the address bar.
And the code in the To (Partners) field that gets partner recipients ids can be as follows:
${ ','.join(map(str, user.env['generic.team'].browse(4).team_member_ids.mapped('user_id.partner_id.id'))) }
Advanced Settings
We can also specify the translation language of the team leader for the current email.
${ user.env['generic.team'].browse(4).leader_id.lang }
An email example of the configured template looks like this:
Automated Action: send email on SLA Limit to a Team leader
And the last action we need to set up is an action that will automatically send an email to the team leader if SLA of the unassigned request fails.
The action will have the following configuration:
Email Template config:
-
Subject
SLA Failed: ${object.display_name}
-
Email Text Template
Dear ${ user.env['generic.team'].browse(4).leader_id.name or ''}, ${object.sudo().type_id.display_name} ${object.name} has Failed the SLA.
Email Configuration
-
From
${(user.company_id.email and '"%s"
-
To (Partners)
${ user.env['generic.team'].browse(4).leader_id.partner_id.id }
This code will get the partner id of the team leader
Advanced Settings
The translation language for the team leader is set as in the previous template.
${ user.env['generic.team'].browse(4).leader_id.lang }
Email that will be sent using this template looks like this: