How to send workflow emails at specific times

Hi SuiteCRM experts,

I am working towards moving over from Sage ACT to SuiteCRM and cant figure out how to setup a workflow so that an email is sent out at a specific time.

Our business needs several emails to be sent at specific times in the day.
It seems that this functionality is not built into suitecrm but was wondering if anyone could suggest a work around.
I cant modify the workflow scheduler because it will affect other workflows that i have set.

So the exact functionality i need is:
There is a field called appointment_date.
4 days before this date at 9am i need a specific email sent.
1 day before this date at 5pmm i need a specific email sent.
On the day of the appointment at 7pm i need another email sent
Every year on the one year anniversary of the appointment i need another chain of emails to be sent.
All emails have different content.

  1. Is there a logic hook for the work flow that i could use?
  2. have any of you encountered a situation like this and figured out a workaround?
  3. i also would like to schedule calls at specific times of the day ising workflows

I think you may want to utilize scheduled jobs to accomplish this. You can run those at intervals of your choosing and run queries such as query records with a start date in 4 days and do pretty much anything you want at that point.

As for scheduling calls I think you may be able to set the start time using the workflow but if not this could be done in a logic_hook.

Hope that helps.

This link may help get you started:
http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_6.5/Application_Framework/Job_Queue/Schedulers/Custom_Schedulers/

Thanks for the response Shad. I spent some time considering your proposal. However, it was quite complicated.
I took a step back and figured out a very simple solution to the problem. Posting it here so that it can help others.

Basically what I am trying to do is ensure that workflow emails are sent out at a specific times of the day based on an Appointment field (DateTime field).

What I did was

  1. Created 2 new DateTime Fields. appointment_date_c and appointment_date_workflow_c
  2. Created a before save logic hook that copies appointment_date_c field to appointment_date_workflow_c but sets the time to 00:00 (this is important)
  3. Setup my workflow condition as such :
    Contacts - Appointment_Workflow - Less Than - Date - Now + 87 Hours

What this does is sends an email exactly 87 hours before 0:00 on the Appointment Date which calculates to be 9am 4 days before the appointment. You can now modify the number of hours (or even use minutes) to ensure that emails are sent at exactly the time of day that you prefer.

Why create the logic hook to set the hours and minutes to 00?
Because if you don’t do that, the email will fire at 87 hours before the time in the appointment_date_c field. So it will not be 9am, it will be some other time based on what the time value entered in the field. Without this step, if the appointment_date_c field contains 11/21/2016 01:00 am, the email will fire at 10am not 9am.

Logic hook code for reference:

<?php
ini_set('display_errors', 1);
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

class UpdateDatesClass
{
  function UpdateDatesFunction($bean, $event, $arguments)
  {


$date = new DateTime($bean->appointment_date_c);
$date->setTime(00,00);
$appointment_temp_var = $date->format('Y-m-d H:i:s');
$timedate = new TimeDate();
$bean->appointment_date_workflow_c = $timedate->fromString($appointment_temp_var, $current_user)->asDb();

 }
}
?>

I still wish SuiteCRM had a simple time option when you create a workflow. It would make life a lot easier. I think times are important in workflow. The time an email is sent makes a big impact on whether an email is opened and relevant information reaches the customer.

2 Likes

Nice. Glad you found a pretty simple solution

We have pretty much the same issue, we have a specific workflow which should update a record but we want to run it exactly @ 9:30 AM every working day. We have many other workflows which runs every 5 minutes, so we can not change the scheduler. Does anybody know how can we accomplish that? thanks.