Jump to content
Psypher

ANSWERED New to Swyx and a little rusty in VB.

Recommended Posts

Hello Swyx users!

I am new to Swyx and have had a hard time trying to understand the basics and how everything is connected.

 

My main focus is the GSE and writing scripts.


I havn't really found a good way to view code (using Visual Studio some of the time, but I always have to adapt the code to work in GSE) and the syntax in general feels a lot like trial and error and have been taken A LOT of time.


My testing at the moment is changing something and calling the number to see if it works or if the line is busy (failing) and then checking the relative sparse information in the Event Viewer and trying some new code.

I am trying to make a function that checks if a caller have been calling before within X minutes and if so, it should redirect the call to the last person the caller spoke to.

 

My code is looking like this:

 

Const sTimeIntervalForRecall = "60"
'On Error Resume Next

Function bCallerCalledBefore()
	bCallerCalledBefore = False
		
	' Define Connectionstring
	Dim sDsn
        sDsn = "Driver={SQL Server Native Client 11.0};Server=.\SQLExpress;Database=IpPbxCDR;User Id=CDR;Password=CDR;"

	' Open connection to database
       	Dim db
	Set db = CreateObject("ADODB.Connection")
       	db.Open(sDsn)

       ' Open recordset
        Dim sSQL        
       	sSQL = "SELECT CallId, StartTime, DATEDIFF(minute, StartTime, GETDATE()) FROM IpPbxCDR WHERE OriginationNumber = '" + CallerNumber() + "' AND DATEDIFF(minute, StartTime, GETDATE()) < " + sTimeIntervalForRecall + " ORDER BY StartTime DESC;"
	
	Dim rs
       	'Set rs = CreateObject("ADODB.Recordset")
        Set rs = db.Execute(sSQL)

	If rs.BOF = False And rs.EOF = False Then
		bCallerCalledBefore = True
	End If	
End Function

 

The code is mostly made of syntax that was accepted and not necessarily the best practice.

 

I also tried to add some try-catch and On Error GoTo, but without any success.

 

I am interesting in both ressources, best practice, info, tools, work procedures, etc. that could make my problematic and slow work procedure much easier and faster. 

 

Kind Regards

 

Kasper S.

 
 

Share this post


Link to post
Share on other sites

Hello Kasper,

 

welcome to SwyxWare ;) 

 

First of all, the most important link when it comes to Extended Call Routing:

 

About "try catch": never ever place your "on error resume next" outside of a function definition. By that you disable the default error handling globally within the call routing. Instead just place it in your own functions only. By that the default error handling is switched off in your function only. Every where else the default error handling remains.

 

Once you have switched the default error handling off, you need to check for errors yourself. Sort of "try catch".

 

On Error Resume Next

x = 1 / 0

If Err <> 0 Then
	PBXScript.OutputTrace "Error (" & Err & "): " & Err.Description
End If

Err.Clear

 

As the call routing is executed by the Swyx Server you can't write your debug information into any console or window. Instead you can (have to) write into the SwyxServer trace file:

The following link explains how to find your own tracing back in the jungle of the server trace file:

 

Hope this helps...

 

Share this post


Link to post
Share on other sites
3 hours ago, Psypher said:

sSQL = "SELECT CallId, StartTime, DATEDIFF(minute, StartTime, GETDATE()) FROM IpPbxCDR WHERE OriginationNumber = '" + CallerNumber() + "' AND DATEDIFF(minute, StartTime, GETDATE()) < " + sTimeIntervalForRecall + " ORDER BY StartTime DESC;"

 

One more thing: in VBScript you use & instead of + to concatenate strings.

 

Share this post


Link to post
Share on other sites

Hello Tom.

 

I was away from job and have been occupied moving in private. I read your good replies the day you posted them, but was first able to reply now - sorry about that, they are much appreciated.

 

I updated my code with all your advices (I hope) and with a little errorhandling and logging.

 

It now look like this:

Const sTimeIntervalForRecall = "60"
Dim sNumberToRedirectTo

Function bCallerCalledBefore()
	On Error Resume Next
	bCallerCalledBefore = False
		
	' Define Connectionstring
	Dim sDsn
        sDsn = "Driver={SQL Server Native Client 11.0};Server=.\SQLExpress;Database=IpPbxCDR;User Id=CDR;Password=CDR;"

	' Open connection to database
       	Dim db
	Set db = CreateObject("ADODB.Connection")
       	db.Open(sDsn)
	If Err <> 0 Then
		PBXScript.OutputTrace "FEJL (" & Err & "): " & Err.Description
		Exit Function
	End If
	Err.Clear

       ' Open recordset
        Dim sSQL        
       	sSQL = "SELECT TransferredToCallId FROM IpPbxCDR WHERE OriginationNumber = '" & CallerNumber() & "' AND DATEDIFF(minute, StartTime, GETDATE()) < " & sTimeIntervalForRecall & " ORDER BY StartTime DESC;"
	
	Dim rs
        Set rs = db.Execute(sSQL)

	If rs.BOF = False And rs.EOF = False Then
		bCallerCalledBefore = True
		sNumberToRedirectTo = rs("TransferredToCallId")		
		PBXScript.OutputTrace "OMSTILLER TIL NUMMER: " & sNumberToRedirectTo
	End If

	rs.Close()
    	rs = Nothing

	db.Close()
	db = Nothing
End Function

It still feels like a little steep learning curve and still some trial and error, but with logging and better errordescriptions I hope I am on my way.

 

The SQL actually worked with the + instead of &, but I changed it and will try to remember that syntax. 

 

I also have to look more into all the ressources in the ECR Useful Link Collection.

 

Thanks a lot.

 

Kind regards

 

Kasper S.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

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