App Routines allow you to schedule tasks to be run at a later date. In this scenario, we will create a way to send out an email based on an email template at a specific time.
Note: This customization requires a basic knowledge of Method customization, such as loops, action results, and conditional statements. |
In this article, we will cover:
Scenario description
For this scenario, the email will be scheduled by the signed-in user by setting the activity type to "Scheduled Email", a new type we will add for this example. The Start Date will be used to indicate the actual date the email should be sent.
Although the activity will be manually created for this example, you can use this article as a starting point on how an app routine can be used to schedule emails at a later date.
Create a new activity type: Scheduled Email
We plan on having the app routine loop through the Activity table, looking for activities of type Scheduled Email. Since this type doesn't exist, we will need to create it.
Go into the Preferences of the Activities App.
Expand Default Activity Type and then select Add / Edit List. (Note: There are many ways to edit this list, but this is one of the quickest from the dashboard).
Create a new activity type as shown below:
Activity Type: Scheduled Email
Activity Category: Email
Default Activity Status: Not Started
Show on Calendar?: Unchecked.
Cause Reminder?: Unchecked.
Save the new activity type and return back to the Activity Type list.
You will need the RecordID for your new Activity type, however, there is no way to get this RecordID off of the screen. Note in the below image, the RecordID is not shown. You will need to customize the editable grid to show the RecordID field.
Create the Email Template
The scheduled email will be based on an email template from the Send Email app. Creating an email template is beyond the scope of this article, however, refer to "Create a Basic Email Template".
For this scenario, we copied the Web To Lead Contact Notification email template, which has the following merge fields in it:
Company.CompanyName
Contacts.FirstName
Contacts.Email
Before sending the email, we will merge the above fields so it properly shows the recipients information, as well as our company's info.
Please make note of the Record ID of the email template you create. This will be used later on when we pull in the email template.
Create the App Routine
Now that we have a way to identify the activity as a scheduled email, we can create the App Routine. An App Routine is at the app basis, and you can choose whether or not to put it in the Acitivity App, or the Send Email app. In this case, it doesn't really matter where it goes, but since it's sending out an email, I'll place it in the Send Email app.
Manage the Send Email app.
Since this is a stock app we're managing, only a few options will be available to you. Select App Routines.
Click the New Routine button to create a new app routine.
Enter a Name and Description for your new app routine and then click Save.
This will create a new app routine, but there's nothing in it. Next up we need to add some actions to it.
Build the App Routine
Since this app routine will be scheduled, it won't need any inputs nor will it output.
▶ Click Edit Draft Actions to bring up the action editor.
You will then do the following steps to create this routine:
▶ Add the Loop through Table action.
Set the table to the
Activity
table.For the Where criteria:
ActivityType - RecordID
= (Record ID for your new Scheduled Email type)DueDateStart
=Current Date and Time
Compare the dates using
Date
only, not time. This will only pull in activities scheduled for the date as specified in DueDateStart.
ActivityStatus - RecordID
NOT EQUAL to (Record ID for the Completed Activity Status. You will need to find that via the Activity Status grid, which is usually "3
".)
The rest of the following actions should go within the Loop through Table action.
▶ Add the Retrieve Values From Table action to pull in the email template.
Select a table:
EmailTemplate
For the Where criteria:
RecordID
= (RecordID for the Email template you created above)
For Field(s) to retrieve you will create a number of action results for each field you retrieve:
EmailBCC
→ "resultEmailBCC
"EmailBody
→ "resultEmailBody
"EmailCC
→ "resultEmailCC
"EmailFrom
→ "resultEmailFrom
"EmailSubject
→ "resultEmailSubject
"
▶ Add a Conditional statement to make sure there is a from Email address.
For the conditional statement criteria make sure all the following are true:
resultEmailFrom
is Empty.resultEmailFrom
is equal to a blank Text field.
▶ Within the conditional statement, add a Retrieve Values From Table action.
Select a table:
Users
For the Where criteria:
RecordID
= from the Loop, theAssignedTo_RecordID
.
For Field(s) to retrieve you will create a number of action results for each field you retrieve:
UserName
→ "resultAssignedToUserName
"UserEmail
→ "resultEmailFrom
"
Outside of the conditional statement, but still within the Loop, we will be using three Character Functions actions. Each will merge fields for the Email subject and Email body.
▶ Add the first Character Functions action to field merge the Company for the subject.
Function:
Replace Merge Fields
Using this text: Action result
resultEmailSubject
Merge data from this table: Text - "
Company
"Using this RecordID: Number - "
1
"Store result in: Action result -
resultEmailSubject
▶ Add the second Character Functions action to field merge the Company for the body.
Function:
Replace Merge Fields
Using this text: Action result
resultEmailBody
Merge data from this table: Text - "
Company
"Using this RecordID: Number - "
1
"Store result in: Action result -
resultEmailBody
▶ Add the third Character Functions action to field merge the Contact for the body.
Function:
Replace Merge Fields
Using this text: Action result
resultEmailBody
Merge data from this table: Text - "
Contacts
"Using this RecordID: From loop -
Contacts - RecordID
Store result in: Action result -
resultEmailBody
Note: When specifying a table in a Character Functions action, you are not given a dropdown but are typing in the table name. Make sure you type the name exactly! |
▶ Send off the email with the Send Email action.
Sender's email address:
resultEmailFrom
Sender's name:
resultAssignedToUserName
Recipient email address: From loop -
ContactsEmail
Check Include CC and BCC
CC's email address:
resultEmailCC
BCC's email address:
resultEmailBCC
Subject:
resultEmailSubject
Body:
resultEmailBody
Finally, we will update the activity so we know that it's been sent.
▶ Add the Character Functions action to append to the activity comments section.
Function:
Join
Join this: From loop
Comments
With this: Text - "
[EDIT] SCHEDULED EMAIL SENT ON
And then this: From Session -
Current Date / Time
Store result in: Action result -
resultComments
▶ Add the Update Fields in Table action to update the activity.
This is important so we don't send the email out again. We only send out emails for activities that are not completed.
Select a table:
Activity
Update records where:
RecordID
= Loop -RecordID
For Field(s) to update :
ActivityStatus - RecordID
→ Number "3
" (Marks it complete)Comments
→ Action result -resultComments
ActualCompletedDate
→ From Session -Current Date / Time
EmailBody
→resultEmailBody
EmailSubject
→resultEmailSubject
And the routine is complete!
Here is the final Action List.
Schedule the App Routine
Now that the app routine is finished, we can publish it, and schedule it.
Close the Action List editor if it isn't closed yet.
On your newly created App routine screen, open up More Actions button.
Select Publish Draft.
At the top, you will receive notifications the app routine is published.
Go back to the More Actions button again, but this time, select Schedule.
Select a time block that runs on a Daily schedule. This app routine will run on a daily basis and check the activity table on that day for any emails that are scheduled to run that day.
Click Save and your app routine is now scheduled to run!
Monitor your App Routines
The trickiest thing with app routines is making sure they ran on time. It is best practice to always test this first.
First, let's see if it's scheduled properly.
From the Profile Menu, choose Account Settings and then select App Routines to view all the App Routines on your account, not just the ones in the Send Email app.
Click View routine schedules.
On this screen, you can see when the routine is scheduled to next run under Next Run Date. You can also check when it last ran as well.
Once you've verified your routine is scheduled, you will want to see if it properly ran. After the run date has passed, go and check your completed routines by clicked View Routines on your App Routines page.
On this page, we can check on how our app routines did after they were scheduled to run:
In the above example, we can see our app routine that ran at 2:57pm completed successfully. However, the one that ran at 1pm failed!
By clicking the row with the failed status, you can see more details on why it failed. In the below example, it was because I accidentally put in the wrong email for the ToField and so it was empty when it ran.
However, we're done! I hope you can get started on making your own app routines to schedule emails.