Jump to content

Blogs

Our community blogs

  1. VBScript Lua

     

    When it comes to develop call routing scripts with some own VBScript code in it, it might become handy to be able to have a look on what your code is doing.

     

    There are lots of so called "debugging" possibilities, but at this point you have to believe me, the only really reliably working method is placing your own log/trace information into the server trace file. 

     

    Before you say that those trace files are way too large and confusing for you, they are not, once you know how to read them and how to filter the stuff you are interested in out. In the forum post "How to filter SwyxWare traces for call routing output of a single call" I have explained already in detail how this can easily be done. So lets focus on how to get your own information into the server trace file.

     

    This can simply be done with PBXScript.OutputTrace (Vbs)/ PBXScript.OutputTrace() (Lua).

     

    For VBScript based Call Routing:

    PBXScript.OutputTrace "Hello World!"

     

    For Lua based Call Routing:

    PBXScript.OutputTrace("Hello World")

     

    So what should be written into the server trace and what not? And how will I find my own trace output quickly and easily?  

     

    By taking a look into the server trace file you figure that the SwyxWare traces quite a lot of stuff, not only errors but also tons of other information and events. You should do the same in your own VBScript/Lua code as well. Do not only trace errors your run into but also every kind of information that might become useful later on when you have to analyse the call routing if for some reason it doesn't work anymore like the many months before. The more information you place into the trace file the more easy it will become to pin point a problem later on. You might not even have to get into the script and work yourself into it if the traces are already informative enough.

     

    Lets assume you have written yourself a VBSscript/Lua function to do what ever you need to do, placed it into the Start block and call it later on e.g. in an Evaluate block.

     

    Taking all said above into consideration, that following is something like a "best practice" function template in terms of tracing.

     

    For VBScript based Call Routing:

    Function DoWhatever ( Parameter1, Parameter2 )
    
        PBXScript.OutputTrace "---------> DoWhatever"
        PBXScript.OutputTrace "Parameter1 = " & Parameter1
        PBXScript.OutputTrace "Parameter2 = " & Parameter2
    
        On Error Resume Next
    
        Dim bReturn
        bReturn = False
    
        ' do what ever your function needs to do
        ' ...
        If Err <> 0 Then
            PBXScript.OutputTrace "Error while doing something!"
            PBXScript.OutputTrace "(Err) " & Err.Description
        Else
            PBXScript.OutputTrace "Successfully did something"
        End If
    
        ' if you "calculate" something, it is always a good idea to trace the result of it
        Dim sSQL
        sSQL = "SELECT * FROM MyTable WHERE value1 = " & Parameter1 & " AND value2 = " & Parameter2
        PBXScript.OutputTrace sSQL
    
    
        DoWhatever = bReturn
    
        PBXScript.OutputTrace "bReturn = " & bReturn
        PBXScript.OutputTrace "<--------- DoWhatever"
    
    End Function

     

    For Lua bsed Call Routing:

    function DoWhatever ( Parameter1, Parameter2 )
    
        PBXScript.OutputTrace ("---------> DoWhatever")
        PBXScript.OutputTrace ("Parameter1 = " .. Parameter1)
        PBXScript.OutputTrace ("Parameter2 = " .. Parameter2)
    
        local bReturn = false
        local oResult = nil
    
        -- do what ever your function needs to do
        -- ...
        if (oResult == nil) then
            PBXScript.OutputTrace ("Error while doing something!")
        else
            PBXScript.OutputTrace ("Successfully did something")
        end
    
        -- if you "calculate" something, it is always a good idea to trace the result of it
        local sSQL
        sSQL = "SELECT * FROM MyTable WHERE value1 = " .. Parameter1 .. " AND value2 = " .. Parameter2
        PBXScript.OutputTrace ("sSQL = " .. sSQL)
    
        PBXScript.OutputTrace ("bReturn = " .. tostring(bReturn))
        PBXScript.OutputTrace ("<--------- DoWhatever")
    
        return bReturn
    end

     

     

    Lets go through the template, step by step...

     

    The first and the last thing you function should do it to trace that you have entered and left it again.

     

    For VBScript based Call Routing:

    PBXScript.OutputTrace "---------> DoWhatever"
    
    PBXScript.OutputTrace "<--------- DoWhatever"

     

    For Lua based Call Routing

    PBXScript.OutputTrace ("---------> DoWhatever")
    
    PBXScript.OutputTrace ("<--------- DoWhatever")

     

    The arrows should tell you that you go into your function and go out of it again. All trace lines in between these two arrow lines will be made by your function. So they also help to find your stuff quickly.

     

     

    If your function takes parameters it is a good idea to trace them. If your function doesn't work and it get already come crap parameters it is not surprising that it fails later on.

     

    For VBScript based Call Routing:

    PBXScript.OutputTrace "Parameter1 = " & Parameter1
    PBXScript.OutputTrace "Parameter2 = " & Parameter2
    

     

    For Lua based Call Routing:

    PBXScript.OutputTrace ("Parameter1 = " .. Parameter1)
    PBXScript.OutputTrace ("Parameter2 = " .. Parameter2)

     

     

    For VBScript based Call Routing: If you have disabled the standard error handling (will be part of a future blog post) you need to check every "dangerous" call yourself, if it succeeded or not. For example you try to write something into a text file it could happen that the file doesn't exist or is read only. Or you try to access a database which is currently not reachable. So if you check for the outcome of such a call do not only trace errors but also that it succeeded.

    If Err <> 0 Then
        PBXScript.OutputTrace "Error while doing something!"
        PBXScript.OutputTrace "(Err) " & Err.Description
    Else
        PBXScript.OutputTrace "Successfully did something"
    End If

     

    For Lua based Call Routing:

    if (oResult == nil) then
        PBXScript.OutputTrace ("Error while doing something!")
    else
        PBXScript.OutputTrace ("Successfully did something")
    end

     

     

    If you calculate something within your function, e.g. build an SQL statement to run against a database and use some current values (e.g. the function parameters) to do so, it is a good idea to write the result of this into the trace. To stay with the SQL statement example this will enable you later on to copy&paste the statement from the trace file and test it directly against your database.

     

    For VBScript based Call Routing:

    Dim sSQL
    sSQL = "SELECT * FROM MyTable WHERE value1 = " Parameter1 & " AND value2 = " & Parameter2
    PBXScript.OutputTrace sSQL

     

    For Lua based Call Routing:

    local sSQL
    sSQL = "SELECT * FROM MyTable WHERE value1 = " .. Parameter1 .. " AND value2 = " .. Parameter2
    PBXScript.OutputTrace ("sSQL = " .. sSQL)

     

     

    And finally, if your function returns a value, just trace this value.

     

    For VBScript based Call Routing:

    PBXScript.OutputTrace "bReturn = " & bReturn
    

     

    For Lua based Call Routing:

    PBXScript.OutputTrace ("bReturn = " .. tostring(bReturn))

     

     

    You don't need to put all trace stuff into your function from the beginning, while you are still developing it. But once it is finished and tested you should put trace output in it.  You can't trace too much information, just too few. The more information you trace the more easy it will become later on to identify a problem if the call routing script ceases to work.

     

     

    Enjoy!

     

    PS: don't miss to take a look into the ECR Useful Link Collection

     

  2. Tom Wellige
    Latest Entry

    By Tom Wellige,

    This post sums this great article series up. Mirjam spent quite some time to identify all those tips and to publish them here on Swyx Forum.

     

    As the article series dates some years back there had been a couple of articles I have not re-posted again, simply because they were not valid with a current SwyxWare version anymore.

     

    But the vast majority of the tips is still valid with current SwyxWare versions and that's why I decided to re-post them to make them available again after the old Swyx Forum went offline.

     

    Thank you very much Mirjam for all your efforts!

     

  3. A common feature request I have had over the years is a Call Park feature, and the usual stock reply to Can Swyx Do..... is NO! but...... of course this is software and anything is possible. I have seen a number of ways of implementing a call park feature some really clever ones that use the conference bridge facility in Swyx to some not so clever ones using analog adaptors to have live logged on extensions which are used to pick up from... sudu call park.
     
    Before I saw the conference room version written by Tom I had a go myself and came up with this solution a couple of years ago and put it online. Recently a couple of requests came in for the source code so I thought I would upload it here.
     
    This is another illustration of how different solutions to problems can be developed with Swyx, there is no right or wrong way, they either work or don't.

     

     

    So next time someone asks if "Swyx can do .........  ?",  reply  "No it can't, but you can"  🙂

     

     

     

     

    Call Park.zip

     

     

  • Blog Statistics

    • Total Blogs
      4
    • Total Entries
      81
  • Blog Comments

    • I have just updated the download link in the article with a correctly working version.  
    • Hi Mark,   do you still have a working version?   Thanks      
    • Nein, das Skript läuft auf JEDER SwyxWare Version. Das ist das schöne am Call Routing     Ich habe aber nochmal etwas genauer nachgesehen, und einen logischen Fehler gefunden. Der ist nun behoben und das Skript läuft einwandfrei auf meinem 13.25er Testsystem. Der Download oben im Blog Post ist aktualisiert.   Das war allerdings nur ein logischer Fehler, d.h. das Ende des Urlaubs wurde nicht richtig erkannt. Das hat aber zu keinen Skript/Ruf Abbruch geführt. Das klingt mir ehe
    • Hallo Herr Wellige 😀   ich bin gerade dabei ein Call Routing zu bauen, wo die Nutzer "einfach" Ihre Urlaubszeit eintragen können. Das hier angebrachte Skript funktioniert leider nicht mehr, das Gespräch wird beendet. Gibt es hier ggf. ein Update für die momentan aktuellste Version 13.25?   Danke schon einmal M. Schulze   getestet mit VBS nicht LUN
    • Hello Tom,   thanks for your reply.   As we´re not running the server on premise, I´ll have to make some calls to find out how to get my hands on the logfiles. The only logs we have are the mmc logs from the maschine the swyxware administration is running on.   And my usual called tech guy seems to be in holidays already  I´ll come back as soon as I get any info - when ever that will be.  
×
×
  • 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.