Firing Business Rules based on the business hours of a queue
One of our customers posed an interesting problem to me this week. They have offices in different locations, in different time zones, with different business hours. The employees in these offices work on different hours from one another, meaning that while one group is working, another group is not working, and vice-versa. The issue comes in when one group dispatches a case to a queue to be worked by the other group. More specifically, the issue is when the queue members should get notified by RuleManager. If the queue members are off-hours, then they should get notified as soon as their next work day starts. Seems like it should be straight-forward. Let’s give it a go.
First Try
Let’s create a specific test example to illustrate the notification process.
- I created two sites, the Texas Support Center (in CST), and the California Support Center (in PST).
- I set the business hours for the Texas center to be Monday-Friday, from 8:00 AM – 12 noon.
- I set the business hours for the California center to be Monday-Friday, from 1:00 PM – 5:00 PM.
- I created an employee named Cali, who works for the California Support Center.
- I created an employee named Tex, who works for the Texas Support Center.
- I created a Texas Support Queue, and made Tex a member of this queue.
- I created a new business rule:
Object Type: | Case |
Rule Name/Description: | Notify all queue members upon dispatch |
Start Event: | Dispatch |
Cancel Events: | None |
Conditions: | None |
Action Title: | Notify Queue Members |
Who to Notify: | Current Queue Members |
Start Action: | 0 minutes |
from: | Event Creation |
Using: | Elapsed Time |
Message: | [Object Type] [Object ID] has been dispatched to queue [Current Queue]. |
Log in as Cali during the afternoon (when Tex is not at work) create a new case for a customer. Dispatch the case to the Texas Support Queue.
Observe the Notifications: Tex gets notified immediately.
No good. Tex is outside his business hours.
So why didn’t this work? Because the rule is setup to use Elapsed Time, thus RuleManager ignores all business calendars.
Second Try
Let’s change the business rule. Specifically, change which Calendar RuleManager is Using, so that it uses Support Business Hours.
Using: | Sppt Bus Hrs |
Log in as Cali during the afternoon (when Tex is not at work), create a new case for a customer. Dispatch the case to the Texas Support Queue.
Observe the Notifications: Tex gets notified immediately.
No good. Tex is outside his business hours.
But we’re using Support Business Hours, so at first glance it should have worked. So why didn’t this work? Because the Support Business Hours is based on the calendar the owner of the case (or, if the owner doesn’t have a calendar, the site of the owner). Which, in this case, is still Cali. Tex (or someone else from the Texas Support Center) doesn’t become the owner until he or she accepts the case from the queue. So, RuleManager sees that Cali is still the owner, evaluates the business hours of the owner, sees that Cali is on work hours, so RuleManager sends the notification to the queue members immediately.
Time to Customize
What we want is for RuleManager to honor the business hours of the queue. But a queue doesn’t have business hours. Sites (and employees) do. So, let’s make the queue have a calendar by making the queue belong to a site.
1. Create a new relation between the site and the queue
A simple SchemaScript with the Dovetail SchemaEditor does the trick:
<schemaScript xmlns="http://www.dovetailsoftware.com/2006/10/SchemaScript.xsd"> <addRelation name="site2queue" type="OneToMany" table="site" inverseRelationName="queue2site" inverseTable="queue" /> </schemaScript> |
2. Create a new user defined calendar, that tells RuleManager how to get from the case to the business calendar
We’ll create a dat file, and import it using ArchiveManager (or dataex)
object type="prop_name" name="usercal150" unique_field = "obj_type","prop_name" fields obj_type = 0; prop_name = "@USERCAL150"; path_name = "case_currq2queue:queue2site:site2biz_cal_hdr:objid"; end_fields end_object name="usercal150" |
3. Create a new user defined calendar time zone, that tells RuleManager how to get from the case to the site (and a site will have an address with a time zone)
We’ll create a dat file, and import it using ArchiveManager (or dataex)
object type="prop_name" name="usercaltz150" unique_field = "obj_type","prop_name" fields obj_type = 0; prop_name = "@USERCALTZ150"; path_name = "case_currq2queue:queue2site:objid"; end_fields end_object name="usercaltz150" |
< /p>
4. Relate the Texas Support Queue to the Texas Support Center Site
We’ll create a dat file, and import it using ArchiveManager (or dataex)
(In my database, the site_id of the Texas Support Center is 3)
reference type="site" name="texas" object type="queue" name="texas_queue" |
The "right way" to do this is to modify the Queue detail page in Dovetail Admin, allowing an admin to select the site that this queue belongs to. This would be much nicer. I’ll leave this task as an exercise for the reader.
5. Add this calendar to the Using drop-down list in the Business Rule Action Page in Dovetail Admin (or the form, if using the Clarify Client)
If using DovetailAdmin for managing Business Rules, simply add a new entry to the DdlActionUsing function in $dovetailadmin/pages/biz_rule/inc_lists.asp:
out += ‘<option value="150">Queue Business Hours</option>’;
If using the Clarify Client for managing Business Rules, add your new calendar to the EL_TIME_TYPE control on form 474.
6. Modify the rule to use the new calendar:
Using: | Queue Business Hours |
Third Time’s a Charm
Log in as Cali during the afternoon (when Tex should be sleeping), create a new case for a customer. Dispatch the case to the Texas Support Queue.
Observe the Notifications: None.
Let’s look in the time_bomb table to see if the business rule action was scheduled for the future:
select * from table_time_bomb
objid | title | escalate_time | end_time | focus_lowid | focus_type |
268435684 | BR: Notify Queue Members | 11/6/2007 8:00:00 AM | 1/1/1753 | 268435467 | 0 |
We can see that the notification is scheduled for tomorrow morning at 8:00 AM, just when the day begins for the Texas Support Center.
Exactly what we wanted. Success!
Rock on.