Scheduled Workflows are time based, not event based, so they are triggered on a certain date/time. That totally defines and limits the way they work and the way they must be constructed, which is slightly different than the save event based workflows.
Scheduled Workflows enable you to run periodic tasks to automate your business. You can program the tasks to be executed when a certain time arrives so you can dedicate your attention to other business operations.
The Scheduled Workflow feature offers you a wide variety of launch times to run your workflow. These options are:
Scheduled Workflows are different than event based workflows and their conditions also have a set of restrictions that the other workflows do not have. Most restrictions stem from the fact that we do not have a unique record to execute expressions against. So we cannot use formulas like
because there are no field values to concatenate.
To be honest, this type of expression could be supported, but it would need a big rewrite of the query engine so that the application could convert that into a valid SQL statement and do the concatenation in the database. Currently, the application's expression engine expects to have a valid active record that is being saved, so it can concatenate or, in general, operate with the field values of that record. Since Scheduled Workflows do not have one record to send into the formulas, these cannot be used.
Scheduled Workflows work by constructing an SQL statement that asks the database for records that fulfill the conditions. It gets back a whole set of records, not just one.
Another restriction that stems from this is the use of related entity fields. It is difficult to access fields on related entities in the SQL command that is being constructed, so accessing the fields of an Account from a contact requires some coding that we currently do not have in place.
Finally some operators have no meaning in scheduled workflows, mostly the "has changed" type operators which require a specific action of saving to detect the change between the "before" and "after" values. With scheduled workflows there is no "before" value, we are directly selecting records from the database and they have had no change whatsoever.
As with all other workflow types, you can set conditions on any field type as long as:
You cannot currently use fields from other modules nor use formulas of any type.
To overcome the above restrictions, date fields have some special operators and some special functionality that will permit us to select records based on time which is what this type of workflows is all about.
For date fields we can choose from the next set of operators:
For these operators we can:
Then we have a set of special operators which will take a number of hours or days and calculate a range of dates for the record selection. These are:
Less than hours before
Less than hours later
More than hours before
More than hours later
Less than days ago
Less than days later
More than days ago
More than days later
These divide time into four ranges and permits us to set our target date/time in any one of them. The next image depicts the four ranges and you can get a better understanding looking at the examples below.
Look at the next examples of Scheduled Workflow condition configuration along with the associated SQL obtained using the evalwf.php script.
For the examples below, the workflow itself does not change, only the operators and values of the two fields in the conditions. One field is a date field and the other a time field.
fecha is 2015-03-09 and tiempo is 2:00
fecha is not 2015-03-09 and tiempo is not 2:00
fecha before 2015-03-09
fecha less than 2 days ago and tiempo less than 2 hours before
fecha more than 2 days ago and tiempo more than 2 hours before
fecha in less than 2 days and tiempo less than 2 hours later
fecha in more than 2 days and tiempo more than 2 hours later
Escalate a case if it is opened for more than 4 hours
In this example, we will configure a workflow to escalate a case, if it’s not responded for more than four hours. You can have the workflow either escalate the case to the support manager, or trigger an email alert, or do both. This workflow is executed once in every hour.
Send an email to the customer, 2 days before the invoice due date, if the invoice hasn’t been paid until that date
Scheduled workflows help you to streamline your follow-up process by sending them regular email alerts to get paid punctually. We are going to create a scheduled workflow that automatically triggers an email 2 days before the invoice due date, if the invoice hasn’t been paid until that date. You can have this workflow send an email alert to the sales manager, or customer, or even both. This workflow is executed once in a day on the specified time.
Set automatic follow-ups with the Contacts before an Opportunity is closed
In this example, we will configure a workflow to send an email to Assigned to user when the Opportunity is about to Closed Won. This workflow is executed daily.
Next | Chapter 4: Update Workflow Tasks.