Working with Calendars and Times

This chapter discusses the following:

Introduction

Calculating dates and times plays an important role in ConSol CM workflow programming. For a time trigger (see section Time Triggers), the exact point in time when it is supposed to fire can be set via script. This adds various possibilities in controlling escalation times, reminders for engineers, and other active components of a ConSol CM process. Examples for potential calculations with dates and/or times are:

When you calculate a date and/or time, you have to decide if a business calendar should be used or not. A business calendar defines working hours for a process. It is defined using the Admin Tool and assigned to one or more queues.

For example, the service desk team might have working hours from 8 to 6 for 6 days a week, whereas the administration team works on a 9-to-5 basis, 5 days a week. Using a CM business calendar makes sure that an escalation will not be set during spare time and that non-working hours are not included into the calculation of the elapsed escalation time. Please refer to the ConSol CM Administrator Manual for a detailed introduction about business calendars.

On the other hand, there are examples, when a business calendar is not required but the pure time, based on the regular calendar, should be used. For example, when it is required to get back to a customer three weeks after the initial contact. The following paragraphs will show you examples for both use cases.

1 day means 24 hrs of absolute time, it has nothing to do with the use of a calendar. The calendar only plays a role when the time trigger is activated, then the 24 hrs, i.e 86400000 milliseconds, will be taken as business calendar input (if the calendar is enabled).

Example:
When we have as trigger time 1 day = 24 hrs without calendar, the 24 hrs are calculated like regular time, so the escalation will fire one day later at the same time.
In contrast: When we use a calendar (with, for example, 7 work hrs per work day), the 24 hrs will be split-up according to the calendar, resulting in the firing event more than 3 days later (24 hrs = 3 x 7 hrs + 3 hrs).

Calculating with Dates and Times without a CM Business Calendar

Example: Setting a Time Trigger Time with Dynamic Time Range

Depending on the priority, the time trigger for an escalation is configured:

// prio is 'medium'

def escalationTime = configurationService.getValue("custom-mycompany-properties","escalation.time.medium")

def escalationTimeMillisecs = escalationTime * 60 * 1000L

trigger.setDueTime( escalationTimeMillisecs )

Code example 63: Setting time for a time trigger

Calculating with Dates and Times Using a CM Business Calendar

Example: Using a Time Trigger with a Business Calendar to Calculate Escalation Time (CM 6.9)

Figure 148: ConSol CM Process Designer - Time trigger for escalation 4 hours before deadline

def deadl = ticket.get("serviceDesk_fields.desiredDeadline")

 

// 4hrs before deadline the escalation should be set

// business calendar should be used

// ServiceDeskCalendar is assigned to queue ServiceDesk, this is transparent here

def now = new Date()

 

// time required in millisecds

def four_hours = -4*60*60*1000L

 

// calculate escalation date

def escalDate = BusinessCalendarUtil.getBusinessTime(deadl, four_hours, ticket.queue.calendar)

 

// calculate and set due time

 

def dueTime = escalDate.time - now.time

trigger.setDueTime(dueTime)

Code example 64: Script for time trigger for escalation 4 hours before deadline (method BusinessCalendarUtil.getBusinessTime for CM versions lower than 6.10.6)

def deadl = ticket.get("serviceDesk_fields.desiredDeadline")

if (deadl == null){

println("No deadline set!")

} else {

// log.info """DEADL: ${deadl}: ${deadl.time}"""

// 4hrs before deadline the escalation should be set

// business calendar should be used

// ServiceDeskCalendar is assigned to queue ServiceDesk, this is transparent here

def now = new Date()

// log.info """NOW: ${now}: ${now.time}"""

// time required in millisecds

def four_hours = -4*60*60*1000L

 

// calculate escalation date

def escalDate = BusinessCalendarUtil.getEscalationTime(deadl, four_hours, ticket.queue.calendar)

// calculate and set due time

// log.info """escalDate: ${escalDate}: ${escalDate.time}"""

def dueTime = escalDate.time - now.time

trigger.setDueTime(dueTime)

}

Code example 65: Script for time trigger for escalation 4 hours before deadline (method BusinessCalendarUtil.getEscalationTime for CM versions 6.10.6 and up) (comment-in the log.info statements if you would like to try out the example)

Please remember that the method setDueTime() sets the trigger time (delta) in milliseconds starting from the point in time when the ticket has entered the scope where the trigger is located!

The following methods are available with the class BusinessCalendarUtil. They are helpful for calculating times when a business calendar is in use.