We recently had the opportunity to work with a customer, 2Win Global, who has been a long-time fan of TaskRay. 2Win trains the largest and most successful technology companies globally to improve their sales demos and presentations resulting in improved win-rates and revenue. They’d been hosting all-day training workshops, but now that they were doing lots of coaching over Zoom, they needed to schedule hourly and needed start times for their sessions which were increasingly held in different timezones from the person scheduling them.
We had a unique problem; we implemented TaskRay before transitioning to 100% virtual and discovered that tasks with a start date and end date were no longer enough. We needed start and end times. Enter DayBack; with a few scripts, we could integrate TaskRay into DayBack for complete visibility by the hour. The other huge feature is the ability to see when resources are available, thus improving our team utilization and profitability. The team at DayBack is fantastic, and I can see why they have a perfect five-star rating. It’s a five-star team!”
Ron Kendig, VP 2Win! Global – Ron’s ⭐️⭐️⭐️⭐️⭐️ review of DayBack on AppExchange
Many of their tasks needed to be scheduled for specific times of the day. The customer wanted to take advantage of DayBack’s resource views to track the task owner’s availability and avoid double booking. With a little bit of customization, we added time fields that work seamlessly with TaskRay’s dates.
TaskRay Uses Dates, not Date/Times
TaskRay has two primary date fields used for scheduling. The Start Date field and the Estimated End Date field. DayBack supports this configuration without any customization and works especially well in the Resource List view, where all the tasks assigned to a person are listed without times in their column. For organizations who aren’t using tasks scheduled for specific times, this can be a great view for seeing which tasks are assigned to which people.
Resource Scheduling with Date/Times
Our customer wanted a similar view and wanted to specify times for some tasks while leaving some tasks with just dates. DayBack’s Resource Schedule view is perfect for this as it keeps the tasks without times in the All-Day section at the top of the columns and renders tasks with specific times below.
Adding Times and Timezones to TaskRay
Our customer wanted to add times to tasks so that they would display in the appropriate cell in DayBack; they also wanted to keep all of the date functionality that TaskRay brings to managing dates. Initially, we thought that just adding time fields to the Task object would be all that’s required. But another requirement was that different timezones be supported and take advantage of DayBack’s enhanced timezone support.
Unfortunately, the time fields in Salesforce are “floating” and don’t reflect a specific UTC value that can be interpreted across timezones. The only Salesforce fields that work this way are Date/Time fields. They’re stored as UTC values and then displayed with the appropriate time for each user depending on the timezone specified in the org or user’s settings. This meant that we needed to add new Date/Time fields to the Task object and then keep the date part of them in sync with TaskRay’s native date fields.
We added the two new Date/Time fields: Start Date Time (Start_Date_Time__c) and Estimated End Date Time (Estimated_End_Date_Time__c). We also added a checkbox field for flagging a Task as an All Day task as this is not implicit in Date/Time fields by themselves.
Using An Apex Trigger To Keep Dates and Date/Times Synchronized
We had looked at using Process Builder or Flows to keep the dates and Date/Times in sync, but timezone support is limited, and there’s no support for daylight savings using either of these methods, so we needed to use Apex for this. Fortunately, Apex has robust support for both timezones and daylight savings using the TimeZone class and getOffset method, which accounts for DST correctly. This allowed us to create an Apex Trigger that would update the Date/Times correctly if the dates were edited and update the dates if the Date/Times were edited.
We specified default values for times (if they hadn’t yet been set) and made sure all new tasks had the All Day checkbox turned on by default, so this didn’t affect the user experience. If times had been specified for the task and the date was updated, then the trigger updates the date portion of the Date/Time, keeping the specified time values the same. You can download the trigger as well as the test class which provides 100% code coverage: https://www.seedcode.com/TaskRay/Apex.zip
Now that the dates and Date/Times are being synchronized, our customer could quickly assign times to the tasks by dragging them from the all-day section in DayBack to the appropriate time block. (Dragging tasks into a time slot sets the new Date/Time fields and unchecks the all-day checkbox.)
We can also see that the TaskRay date fields are updated accordingly from the new Date/Time fields so all of TaskRay’s native functionality remains intact.
Soft Roll-out with Formula Fields
To start using DayBack with this configuration, we need to have values in the new Date/Time fields and checkbox. This could have been done using Salesforce’s Data Loader, but another option is to create formula fields for the new fields and the checkbox. These formula fields will look to see if there are values set for the new fields and use those values if they’re present. Otherwise, they will return default values. These formula fields will be populated right away and mapped to the appropriate fields in DayBack without having to do a backfill for existing records.
The formula field for the all-day checkbox can infer that a Task is all-day if the Start_Date_Time__c hasn’t been populated yet, even though the static checkbox field for all-day isn’t checked. It looks like this:
IF( All_Day_Task__c , true, IF ( ISNULL( Start_Date_Time__c ) , true , All_Day_Task__c ) )
For the start and end Date/Times, we can take a similar approach and use formula fields that look like this.
IF( ISNULL( Start_Date_Time__c ) , DATETIMEVALUE( TEXT( TASKRAY__trStartDate__c ) & " 19:00:00") , Start_Date_Time__c )
We do need to provide a default time value, but since all tasks will start as all-day by default, they really don’t affect the user experience since users will be specifying a specific Date/Time when changing them from all-day either in DayBack or in the native TaskRay layout. Eventually, an administrator could determine that all non-archived tasks were created with the new configuration and remove the formula fields. They’d then re-map the static fields in DayBack, but there’s not really any downside to keeping the formula fields in place indefinitely.
We can then set up a simple On Event Save Custom Event Action in DayBack that will prevent DayBack from attempting to edit the formula fields (which would result in an error) and edit the new fields that the formula fields reference. The On Save action looks like this:
if(changesObject.start){ //update the source date time field for start and not the formula changesObject.Start_Date_Time__c = changesObject.start.format(); delete changesObject.start; } if(changesObject.end) { //update the source date time field for end and not the formula //offset the end if all day as Salesforce does not make midnight exclusive var adjustedEnd = editEvent.allDay ? moment(changesObject.end).subtract(1,'days').format() : changesObject.end.format(); changesObject.Estimated_End_Date_Time__c = adjustedEnd; delete changesObject.end; } if( changesObject.allDay === true || changesObject.allDay === false){ //if the allday checkbox is edited, then edit the actual all day field instead of the formula field changesObject.All_Day_Task__c = changesObject.allDay; delete changesObject.allDay; } else{ //explicitly update the checkbox field if it's not changed as the formula value will get updated //if there's an actual start date time changesObject.All_Day_Task__c = editEvent.allDay; }
Benefits to Customizing TaskRay
DayBack can provide powerful new views to TaskRay for managing resources, whether sticking with TaskRay’s native date-only configuration or extending it with Date/Time fields. Although there are some challenges around Timezones and Daylight Savings when incorporating Date/Time fields, Apex triggers and DayBack’s Custom Event Actions provide us with the tools to do this seamlessly without disrupting all the powerful features TaskRay provides.
Going Further
Need help with this mod? Dive in using the code above or get in touch and we can add this to your org as part of an implementation package.
Learn more about TaskRay. Big thanks to Mike Davis at TaskRay for his encouragement and help with this article. You’ll find TaskRay on Salesforce AppExchage with over 250 five-star reviews!
Leave a Reply