Jump to content

#9: Don't be shy, be chatty!

Tom Wellige

68 views

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.

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

 

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

 

 

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.

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.

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

 

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

 

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.

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

 

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

PBXScript.OutputTrace "bReturn = " & 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

 



0 Comments


Recommended Comments

There are no comments to display.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • 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.