Timer Activity Scripting Example
// Pause Workflow for this duration, when this activity closes, the next activity
// will send PIR meeting reminders to attendees
var oneDay = 1*24*60*60;
var threeDays = 3*24*60*60;
var pir = current.u_pir_date.getDisplayValue();
var now = gs.nowDateTime();
var diffSeconds = gs.dateDiff(pir, now, true);
if (gs.isFirstDayOfWeek(pir) == 1){
answer = diffSeconds - threeDays;
}
else{
answer = diffSeconds - oneDay;
}
The sample script calculates the difference between the Post Incident Review (pir) date/time value identified in the record and activity's start date/time. If the PIR meeting is scheduled on the first day of the week, the timer will remove 3 days from the difference, else it will remove one day from the difference.
The gs.dateDiff() method calculated the difference between two dates. The first parameter identifies the start date, the second parameter identifies the end date, and the third parameter returns a Boolean value. If true, the return value will be formatted in number of seconds; if false the return value will be formatted ddd hh:mm:ss.
Most GlideSystem methods return date/time values in GMT. The gs.getDisplayValue() method returns date/time values in the time zone set in the User's record.