Custom VBScript Code - Check for Bank Holiday

Enreach Info
Enreach Info
  • Updated

Summary:

With SwyxWare v4.0 it is possible to define own custom scripts with the Graphical Script Editor (GSE). To create scripts using the GSE you have to license the Option Pack - Extended Call Routing.

This articles describes, how to implement a simple Bank Holiday Check using a text file defining the bank holidays.

Note: an updated version of this script is available on the public Swyx Forum website www.swyx-forum.com. This new version allows beside simple days also times and date/time ranges in it's bankholiday definition file.

Further arcticles of this series:

Information: 

Installation of the example rule

Download the complete example code usig the link at the end of this article and copy all included files into the

c:\gse_demo

To load the BankHoliday.rse file as rule into your Call Routing Manager i.e. Graphical Script Editor please follow these steps:

  • Open the Call Routing Manager.
  • Click the New... button.
  • Select Graphical Script Editor and click on Ok.
  • Within the GSE open the File | Import... menu.
  • Select the BankHoliday.rse. The rule will be imported and your GSE will look like this:

    disp_image_from_blob.jpg
                                                             Graphical Script Editor
  • Save the new rule using the File | Save menu.
  • Close the GSE.
  • Copy the file BankHoliday.txt into the global script folderC:\Programme\SwyxWare\Share\Data\PhoneClient\ScriptsUsing this folder ensures all other users to be able to access it also. The file contains all bank holidays in Germany being valid for all federal states until end of 2005.
  • Activate the rule by moving it to the right list box of the CRM.
    disp_image_from_blob__1_.jpg
                                                    Call Routing Manager 

How it works

Custom code can only be added to the Start rule. All consts, variables and functions you'll define here are available all over the script, i.e. can be used in all blocks e.g. the Evaluate block. Please note, that the final script being created by the GSE places the VBScript statement option explicit to the top of the script. This forces all variables to be used within the script to be declared properly.

disp_image_from_blob__2_.jpg

                              Properties of Start Rule

As you will see in this example a function will be defined within the custom code in the Start rule, which will later be used within a Evalute block.

disp_image_from_blob__3_.jpg

                         Properties of the "Evalute" block

The function IsBankHoliday() checks if a given date (it will be called with the current date) is defined within the BankHoliday.txt file and return accordingly True or False. This is how the code looks like:

  1. ' FileOpen iomode Values
  2. Const fsoForReading = 1
  3. Const fsoForWriting = 2
  4. Const fsoForAppending = 8
  5.  
  6. ' Bankholiday Filename
  7. Const sBHFilename = "bankholiday.txt"
  8.  
  9. Function IsBankHoliday(ByVal vDate)
  10.  
  11.     Dim wsh, fso, file
  12.     Dim sDir, sFile, sLine
  13.     Dim bReturn, nPos
  14.  
  15.     bReturn False
  16.  
  17.     ' get share path by extracting it from user folder 
  18.     sDir = PBXUser.DataFolder
  19.     nPos = InStrRev(sDir, "\")
  20.     sDir = Left(sDir, nPos - 1)
  21.     nPos = InStrRev(sDir, "\")
  22.     sDir = Left(sDir, nPos)
  23.  
  24.     ' Build file name. 
  25.     sFile = sDir & "Data\PhoneClient\Scripts\" & _
  26.       sBHFilename
  27.  
  28.     ' Create FileSystemObejct
  29.     fso = CreateObject("Scripting.FileSystemObject")
  30.  
  31.     ' Open text file
  32.     file = fso.OpenTextFile(sFile, fsoForReading)
  33.  
  34.     Do While (Not (file.AtEndOfStream)) And (Not bReturn)
  35.         sLine = file.ReadLine
  36.         If IsDate(sLine) Then
  37.             If DateDiff("d", vDate, CDate(sLine)) = 0 Then
  38.                 bReturn = True
  39.             End If
  40.         End If
  41.     Loop
  42.     file.Close()
  43.  
  44.     file = Nothing
  45.     fso = Nothing
  46.  
  47.     IsBankHoliday = bReturn
  48.  
  49. End Function

After activating this rule there will be played a "beep" on incoming calls if it is a bank holiday. This "beep" is a placeholder, of course, for your own script.

The definition file

Within the file BankHoliday.txt all bank holidays have to be listed where each date takes its own line. The date format must match to your regional settings on the SwyxServer machine. This example assumes a date format dd.mm.yyyy.

25.12.2002
26.12.2002
01.01.2003
18.04.2003
21.04.2003
01.05.2003
11.05.2003
29.05.2003
09.06.2003
03.10.2003
25.12.2003
...

Please note that this file contains all german bank holidays being valid for all federal state until the end of 2005.

Notes

  • All callrouting scripts, and therefore also your code, runs under the SwyxWare Service Account. Please make sure that this account has the needed priviliges to access the file/database.
  • The script in this example does contain no Error Handling. If an error occurs at runtime, e.g. when trying to access a database, this error will not be handled, the script will stop and the call get lost. If you have enabled Server Tracing for SvrScript on level Info3 you will find the original Microsoft Script Engine error message within the server trace file.

    To get your own error handling you have to disable the standard error handling by the Script

    Engine:

    On Error Resume Next


    Place this line of code at the beginning of your function. Now you have to check for error at every potential place and do your own error handling:

    ' Open connection to Database
    db.Open sDsn
    If Err <> 0 then
         'do something, e.g.:
         FunctionName = False
         Exit Function
    End If

 

References:

This Swyx Forum Wiki article documents the GSE build in functions.

This Swyx Forum Wiki article documents the SwyxServer Script API.

This Swyx Forum Wiki article documents all VBScript build in functions.

The third-party contact information included in this article is provided to help you find the technical support you need. This contact information is subject to change without notice. Swyx in no way guarantees the accuracy of this third-party contact information nor is responsible for it's content.

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Comments

0 comments

Article is closed for comments.