Inspired by a question in the forum I spent a little bit more time not just giving a few hints as answer in the forum, but instead made a complete call routing script from it.
Task: an incoming call should be provided to 4 different engineers, while in week 1 engineer 1 will get the call, in week 2 engineer 2 will get the call, a.s.o.
In the following I will describe the my approach solving this problem and also how to use the resulting call routing scrpt.
VBscript provides a function DatePart which can be used to evaluate the current week of the year. With that number it should be possible to identify a responsible engineer.
There are two approaches possible:
- somehow calculate the engineer from the week of the year number
- use a list of assigned weeks per engineer to identify the engineer from
I have decided to use a list of assigned weeks per engineer as this opens a very easy way of changing the call distribution in case of e.g. annual leave of one engineer.
Dim AssignedWeeks(4) AssignedWeeks(1) = "1,5,9,13,17,21,25,29,33,37,41,45,49" AssignedWeeks(2) = "2,6,10,14,18,22,26,30,34,38,42,46,50" AssignedWeeks(3) = "3,7,11,15,19,23,27,31,35,39,43,47,51" AssignedWeeks(4) = "4,8,12,16,20,24,28,32,36,40,44,48,52"
With having that the rest of the implementation is easy. I have implemented a function GetAssignedEngineer which simply returns the extension of an engineer (which are set via rule parameters in the final script).
This function gets the week of the year number by the already above mentioned DatePart function and then loops through all 4 engineers if this number is part of their assigned weeks list.
Function GetAssignedEngineer PBXScript.OutputTrace "----> GetAssignedEngineer" Dim sReturn sReturn = sDefaultExtenstion Dim nCurrentWeek nCurrentWeek = DatePart("ww", Now) PBXScript.OutputTrace "nCurrentWeek = " & nCurrentWeek Dim i For i = 1 To 4 If IsInAssignedWeeksList(i, nCurrentWeek) Then sReturn = Engineer(i) End If Next GetAssignedEngineer = sReturn PBXScript.OutputTrace "sReturn = " & sReturn PBXScript.OutputTrace "<---- GetAssignedEngineer" End Function
To check for each engineer if the current week is in his list of assigned weeks I have implemented a function IsInAssignedWeeksList which splits the above defined list of weeks into an array and then simply loops through this array to see if the current week is in it.
Function IsInAssignedWeeksList ( nEngineer, nCurrentWeek ) PBXScript.OutputTrace "----> IsInAssignedWeeksList" PBXScript.OutputTrace "nEngineer = " & nEngineer PBXScript.OutputTrace "nCurrentWeek = " & nCurrentWeek Dim bReturn bReturn = False Dim aWeeks aWeeks = Split(AssignedWeeks(nEngineer), ",") Dim y, nWeek For y = LBound(aWeeks) To UBound(aWeeks) nWeek = CInt(aWeeks(y)) PBXScript.OutputTrace "nWeek = " & nWeek If nWeek = nCurrentWeek Then bReturn = True Next IsInAssignedWeeksList = bReturn PBXScript.OutputTrace "bReturn = " & bReturn PBXScript.OutputTrace "<---- IsInAssignedWeeksList" End Function
Please note, that in case the current week can not be found in any of the lists, the function GetAssignedEngineer returns a default destination. This will make sure that if the lists are getting modified and a week will be forgotten to be added, the function will provide a valid destination to connect the call to.
The call routing script becomes straight forward with having all the logic implemented in VBScript code:
All VBScript code can be found in the Start block. The Insert Script Code block is just used to copy the extensions from each engineer which can be comfortable configured as rule parameters into the VBScript code part of the call routing script.
There is also a 5th parameter which defines the default number the call should be delivered to in case a week can't be found in any of the week lists.
To connect the call to an engineer the Connect To block directly calls the GetAssignedEngineer function:
If the call can't be delivered I have just added a Voicemail option to play it simply here.
And this sums the entire call routing up. One might say its overdone, but this is simply my style of call routing scripts, even including tracing information in case one needs to debug the script.
You can use the following link to download the script (please note, that you need to be a logged in user of this forum in order to be able to download any file from here):
To use this file simply open a new empty call routing rule with the GSE and the use File | Import... to import the above .rse file.
A more complete explanation on how to get call routing functionality from A to B can be found in this blog article:
In case you want to learn all the details behind the used rule parameters in this script, the following blog article will enlighten you:
PS: don't miss to take a look into the ECR Useful Link Collection