Schedule a Task
In this exercise you will learn how you can schedule the execution of a task to start on a date in the future.
The user has asked to reserve the parking place for a certain period, set by the ‘From’ and ‘Until’ UI Extension fields. There are 2 tasks in our workflow that should be performed just before the ‘From’ date:
- Reservation of Parking Space – Prepare a Badge (4 hours before the ‘From’ date/time)
- Reservation of Parking Space – Set ‘Reserved’ Sign (1 hour before the ‘From’ date/time)
Also there are 2 tasks that should be performed at the ‘Until’ date/time:
- Reservation of Parking Space – Retrieve Badge (1 hour before the ‘Until’ date/time)
- Reservation of Parking Space – Remove ‘Reserved’ Sign (At the ‘Until’ date/time)
In Xurrent this can be done by setting the ‘Start no earlier than’ field on a task, which is kept in the ‘start_at’ attribute of the task. For the task “Reservation of Parking Space – Set ‘Reserved’ Sign”, you will set the ‘Start no earlier than’ field to be 1 hour before the ‘From’ date.
Go to the task templates and select the “Reservation of Parking Space – Set ‘Reserved’ Sign” task template. Click on the Actions menu item ‘Automation Rules’ to add a new automation rule. Name it ‘Schedule the reserved sign task’.
You want this automation rule to be executed when the task gets assigned. You will now add the right trigger, expression and the condition.
Question:
Why shouldn’t we set this automation rule to trigger when the task is created?
During the approval cycle it could happen that the ‘From’ date on the request was modified. So it is better to wait to set this ‘Start no earlier than’ after the approval cycle, when the task gets assigned. Technically, it is also possible to define this automation rule on the approval task, when the task is set to status ‘Approved’.
You get the request and the ‘From’ date from the request with the following expressions:
request |
workflow.requests[first] |
from |
request.custom_fields.from |
Now, you need to calculate the date and time 1 hour before the ‘From’ date. This is easy: Xurrent lets you perform complex date and time calculations with simple formulas. In this case you subtract 1 hour from the ‘From’ date that you retrieved from the request:
start |
from – 1.hour |
A complete overview of all the Xurrent operators can be found in the Xurrent online help. The page contains a specific section ‘Date & Time Manipulation". You might learn from the page that you could have written the above expression asfrom – 60.minutes
orfrom – 3600.seconds
.
Question:
What if the requester is located in Houston, Central Time Zone (CT), and the Facilities people are in New York, in the Eastern Time Zone (EST)?
Xurrent takes care of the time zones. Date and time are displayed according to the time zone defined in the profile of the user. Internally, all date and times are kept in Coordinated Universal Time (UTC), which is the world’s time standard. This means, however, that when you want to display a date-time to a user, you are better off defining a UI Extension of type date-time. Whilst you can add date-time values in a text field (like a note), they will be displayed in UTC format, which is not user friendly.
What’s left is the Action: you will update the task attribute ‘start_at’ with the following statement:
Update | current record |
Set | start_at = start |
Save your automation rule and test.
Add also the correct automation rules for the other tasks:
- Reservation of Parking Space – Prepare a Badge (4 hours before the ‘From’ date)
- Reservation of Parking Space – Retrieve Badge (1 hour before the ‘Until’ date)
- Reservation of Parking Space – Remove ‘Reserved’ Sign (At the ‘Until’ date)
Your automation rules should now look like this: