Saflet101TimeRoute

last edited byusericonthelimit on 24-Nov-2009

Time-based Routing



Walkthrough


Download Saflet Used in this Walkthrough


For this walkthrough; you will need to be connected to a SafiServer (see Connection to SafiServer from SafiWorkshop). You will also need to create a Project/Saflet with the Custom Initiator selected as the starting initiator (See: Creating a Project and Saflet)

In the Variables pane right click Local and select Create Variable. In the Create New Local Variable dialog, create a variable named myDatetime with the type of Datetime and an Initial value of 9/20/05 9:20 PM.

The string format for a Datetime variable is: MM/dd/yy hh:mm tt



Press OK to create the variable. You should see your variable created in the Variables pane:



Add the following ActionSteps to the work area:

Connect them like this:



We'll connect the first three DebugLogs later.

Double click the TimeBasedRouting Actionstep to brings up editor window. This editor is similar to the Choice ActionStep. You can add multiple time ranges and conditions as separate exit points.

Set the Value field to your variable myDatetime:



Now click the plus (+) button on the side of the Time Ranges box. This will allow you to add a time range option. Enter a name of Office Is Open, select Weekly and select all the boxes except Sat and Sun. Select the Duration radio button for the From time and set it to 8:00 AM to 2:00 PM . Lastly set the Starting from date to a date before the one you set for myDatetime (i.e. 1/1/05). You should have a Time item window that looks like this:



Press OK to add the range

Now add a time range for Lunch; Monday through Friday from 12PM to 1PM:



and add a time range for Staff Meeting; Thursday from 9AM to 10PM:



You should now have something that looks like this:



We now need to make sure these time ranges are in the proper order. The TimeBasedRouting step evaluates an exit path in much the same way as the Choice step does; from top to bottom. This means that the first valid range will be taken. The way that the example is set up; the Lunch and Staff Meeting paths will never be reached because Office covers the whole time range. To fix this use the arrow buttons on the side of the box to move the ranges to this order (move Office is open to the bottom):



Press OK and your TimeBasedRouting should look like this:



Connect the newly formed exit paths to the unconnected DebugLogs



Change the Message field in each of the DebugLog steps to reflect the path (top to bottom):

"Lunchtime";
"Staff in meeting";
"Office open";
"Default: Afterhours";


Save and Publish the Saflet and set it off using the Custom Initiator Launcher



Your Console should look like this:



You can debug this Saflet to get a more granular view of whats happening. You can also change the Initial Value of the myDatetime variable to see the different paths.

Most likely when you use the TimeBasedRouting you'll want to use the current system date to base the routes on. To do this; remove the variable from the Value field in the step (by pressing the red X button to the right of it). Having a blank value will default to the current systems time:

 
Download in other Formats:
markup Markup | pdf PDF | swf SWF | html HTML | word Word

comments Comments (0)