Jump to content
  • LogCallIntoDatabase

    LogCallIntoDatabase

    VBScript

     

    This function logs some details into a database

    Please see the Introduction chapter for some usage instructions.

     

    ' CursorTypeEnum Values
    Const adOpenForwardOnly = 0
    Const adOpenKeyset = 1
    Const adOpenDynamic = 2
    Const adOpenStatic = 3
     
    ' LockTypeEnum Values
    Const adLockReadOnly = 1
    Const adLockPessimistic = 2
    Const adLockOptimistic = 3
    Const adLockBatchOptimistic = 4
     
    ' CommandTypeEnum Values
    Const adCmdUnknown = &H0008
    Const adCmdText = &H0001
    Const adCmdTable = &H0002
    Const adCmdStoredProc = &H0004
    
    
    '----------------------------------------------------------------
    ' Function LogCallIntoDatabase
    '
    ' Logs details of the current call into a database.
    '
    ' Parameter:
    '
    ' Return:
    '   boolean     true - log created, false - error creating log
    '----------------------------------------------------------------
    Function LogCallIntoDatabase
    
        PBXScript.OutputTrace "-----------> LogCallIntoDatabase"
    
        On Error Resume Next 
    
        Dim bReturn
        bReturn = False
    
        Dim sDsn
        sDsn = _
            "Provider=sqloledb;" & _
            "Data Source=***ServerName***;" & _
            "Initial Catalog=***DatebaseName***;" & _
            "Integrated Security=SSPI"
    
        ' open connection to database
        Dim db
        Set db = CreateObject("ADODB.Connection")
        db.Open sDsn
    
        if Err <> 0 then
            PBXScript.OutputTrace "Error opening database!"
            PBXScript.OutputTrace Err & ": " & Err.Description
        else
            ' open recordset
            Set rs = CreateObject("ADODB.Recordset")
            rs.Open "Logging", db, adOpenDynamic, adLockOptimistic, adCmdTable
    
            if Err <> 0 then
                PBXScript.OutputTrace "Error creating new dataset!"
                PBXScript.OutputTrace Err & ": " & Err.Description
            else
                rs.AddNew
                rs("[Number]")    = PBXCall.CallingPartyNumber
                rs("[Name]")      = PBXCall.CallingPartyName
                rs("[TimeStamp]") = Now
                rs.Update
                if Err <> 0 then
                    PBXScript.OutputTrace "Error writing new dataset to database!"
                    PBXScript.OutputTrace Err & ": " & Err.Description
                end if
                rs.close
            end if
    
            Set rs = Nothing
            
            db.close
        end if
        Set db = Nothing
        
        LogCallIntoDatabase = bReturn
    
        PBXScript.OutputTrace "bReturn = " & bReturn
        PBXScript.OutputTrace "<----------- LogCallIntoDatabase"
    
    End Function

     

    This function makes use of the Server Script API functions PBXCall.CallingPartyNumber and PBXCall.CallingPartyName for the call details and PBXScript.OutputTrace to write trace information into the SwyxServer trace file.

     

    You need to make modifications to this example:

     

    Connection String (sDSN)

    The connection string defines the database and the access privileges you want to use to login into the database.
    The Connection Strings page gives examples for any kind of database.
    You should use OLE DB Data Providers, and if possible Trusted Connection instead of Standard Security (username/password) authentication.
    In this case the Windows user the Swyx Server service is running under (by default this is the "SwyxServiceAccount") needs at least read access to your database.

     

    For example, if you want to connect to an MS SQL Server, you select SQL Server from above linked Connection Strings page. Afterwards select Microsoft OLE DB Driver for SQL Server below OLE DB providers. That should bring you here.

     

     

    Logging Table

     

    This example assumes a table Logging with the fields

    • Number (nvarchar(255))
    • Name (nvarchar(255))
    • TimeStamp (datetime)

     

    If your logging table is somehow different you need to modify the function accordingly.

     

     


    Tom Wellige
     Share


     Share




    User Feedback

    Recommended Comments

    There are no comments to display.



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and have taken note of our Privacy Policy.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.