Custom VBScript Code - Call logging into database

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 Call logging into a database (e.g. MS Access).

Other articles in this series are:

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

disp_image_from_blob__3_.jpg
                                   Properties - Insert Call into DB

The function InsertCallIntoDB opens a connection to a database and inserts a new record into the call_loggingtable. This is how the code looks like:

 

  1. ' CursorTypeEnum Values
  2. Const adOpenForwardOnly = 0
  3. Const adOpenKeyset = 1
  4. Const adOpenDynamic = 2
  5. Const adOpenStatic = 3
  6.  
  7. ' LockTypeEnum Values
  8. Const adLockReadOnly = 1
  9. Const adLockPessimistic = 2
  10. Const adLockOptimistic = 3
  11. Const adLockBatchOptimistic = 4
  12.  
  13. ' CommandTypeEnum Values
  14. Const adCmdUnknown = &H8
  15. Const adCmdText = &H1
  16. Const adCmdTable = &H2
  17. Const adCmdStoredProc = &H4
  18. ByVal
  19. Function InsertCallIntoDB(ByVal  callerID)
  20.  
  21.     Dim sDsn
  22.     sDsn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  23.         "Data Source=c:\gse_demo\demo.mdb"
  24.  
  25.     ' open connection to database
  26.     Dim db
  27.     db = CreateObject("ADODB.Connection")
  28.     db.Open(sDsn)
  29.  
  30.     ' open recordset
  31.     Dim rs
  32.     rs = CreateObject("ADODB.Recordset")
  33.     rs.Open("call_logging", db, adOpenKeyset, _
  34.         adLockOptimistic, adCmdTable)
  35.  
  36.     ' create new record
  37.     rs.AddNew()
  38.     rs("callerid") = callerID
  39.     rs("date") = now
  40.     rs.Update()
  41.  
  42.     rs.Close()
  43.     rs = Nothing
  44.  
  45.     db.Close()
  46.     db = Nothing
  47.  
  48. End Function

After activating this rule all incoming calls with be recorded within the database. 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.

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.
  • This example utilizes an MS Access database. For demonstration purpose this is totally fine, but not for production environments! In production environments you should use real databases, like MS SQL Server, only!
  • 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
  • This example show the so called DSN-less Connection to the database. Of course it is possible to connect to any database via ODBC as long as an ODBC datasource is configured on the SwyxServer machine. There is just one line of code to change in the script. Instead of

    sDsn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=c:\gse_demo\demo.mdb"

    You'll find more examples following the link below the references.

    sDsn = "dsn=MyDatabase"

    If your database requires to login the so called Connection String will look like

      sDsn = "dsn=MyDatabase;uid=MyName;pwd=MyPassword"

    You'll find more examples following the link below the references.

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.