Custom VBScript Code - Call logging into textfile (kb2217)

The information in this article applies to:

  • Graphical Script Editor v4.00
  • SwyxIt! v4.00
  • SwyxWare v4.00

[ Summary | Information | Links ]


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 Call logging into a text file.

Other articles in this series are:


Further informations about the new features within the Graphical Script Editor can be found in the article:


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 LogFile.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 LogFile.rse. The rule will be imported and your GSE will look like this:

    Graphical Script Editor
    Graphical Script Editor
    Click to enlarge...

  • Save the new rule using the File | Save menu.
  • Close the GSE.
  • Activate the rule by moving it to the right list box of the CRM.

    Call Routing Manager
    Call Routing Manager
    Click to enlarge...


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.

Properties - Start rule
Properties - Start rule
Click to enlarge...

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 Set Variable block. This is a small trick: we don't need the new defined variable, we use it just to call our function.

Properties - Insert Call into File
Properties - Insert Call into File
Click to enlarge...

The function InsertCallIntoFile opens a text file and appends the caller id together with the current date and time to it. This is how the code looks like:


  1. ' FileOpen iomode Values
  2. Const fsoForReading = 1
  3. Const fsoForWriting = 2
  4. Const fsoForAppending = 8
  6. Const fsoCreateIfNotExist = True
  8. Function InsertCallIntoFile(ByVal callerID)
  10.     Const filename = "c:\gse_demo\test.txt"
  12.     Dim fso
  13.     Dim file
  15.     ' Create FileSystemObejct
  16.     fso = CreateObject("Scripting.FileSystemObject")
  18.     ' Open text file
  19.     file = fso.OpenTextFile(filename, _
  20.       fsoForAppending, fsoCreateIfNotExist)
  22.     ' Write (append) CallerID into file
  23.     file.WriteLine("""" & callerID & """,""" & _
  24.       CStr(now) & """")
  26.     file.Close()
  28.     file = Nothing
  29.     fso = Nothing
  31. EndFunction

After activating this rule all incoming calls with be recorded within the text file. Note that we exit the script using the Rule skipped block. This will enable us to use other rules after this one within our call routing.



  • 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:


    1. OnErrorResumeNext


    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:


    1. ' Open connection to Database
    2. db.Open sDsn
    3. If Err <> 0 then
    4.     'do something, e.g.:
    5.     FunctionName = False
    6.     ExitFunction
    7. EndIf



As far as software supplied or used by us, includes open source elements the additional terms under apply in addition. An overview which products from the Swyx portfolio include open source elements and which open source license is relevant can be found under

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.


Comment on this article

If we have any follow-up questions, where can we contact you?

E-Mail Address (optional)


This feedback form can't be used for support requests. Those requests must be directed to your Swyx reseller or distributor.