Jump to content

- Miscellaneous

- # Persistent Variables - 6.6 - Usage of Persistent Variables outside of a call routing script

  Followers 0

  VBScript 1.1.0

  The persistent variables have been developed to be used inside of call routing scripts. But as the underlying technology is plain VBScript they can also be used everywhere else where you can use VBScript. Please note that for this to work some adaptions needed to be make in the initial releases.

  The idea behind is of cause to have the same comfort in using persistent variables somewhere else, like e.g. in web pages or standard VBScripts.

  When using the persistent variables outside of a call routing script there is however a difference to the normal usage within call routing scripts: the default Scope is not User but Global. This is because from outside the call routing there is no SwyxWare user easily available and therefore no User scope possible by default. So without defining the scope explicitly, it is global by default.

      Dim NightSwitch
      Set NightSwitch  = new PersistentVariable
      NightSwitch.Name = "NightSwitch"

  If you need to access a variable in the user scope of a specific SwyxWare user all you need to know is it's SwyxWare user id. There is a UserID property that needs to be set in that case.

      Dim RedirectTo
      Set RedirectTo    = new PersistentVariable
      RedirectTo.Name   = "RedirectTo"
      RedirectTo.Scope  = SCOPE_USER
      RedirectTo.UserID = 15

  If you need to access a variable in the group scope of a specific SwyxWare user group all you need to know is it's SwyxWare group id. There is a GroupID property that needs to be set in that case.

      Dim RedirectTo
      Set RedirectTo    = new PersistentVariable
      RedirectTo.Name   = "RedirectTo"
      RedirectTo.Scope  = SCOPE_GROUP
      RedirectTo.UserID = 3

  There are many ways to figure the id of a SwyxWare user or group:

  - Assuming you are accessing the variable also from inside a call routing script you can simply take a look into the PersistentVariables table and take the id from there.
  - You can also trace it into the server trace file from within a call routing and read it from there.
  - Use any of the SwyxWare APIs (Server Script API, Client SDK, ConfigDataStore SDK, Powershell) to obtain it from SwyxWare.
  - and more...

  In order to use the persistent variables in other VBScript file, they need to get included. In a call routing script this is done by adding the PersistentVariable GSE action into the GSE rule. Standard VBScript doesn't doesn't know an include statement, but fortunately there are two environments like a call routing script, that add this missing functionality: Active Server Pages (ASP) and Windows Scripting Files (WSF).

  Active Server Pages (.asp)

  These are simply web pages hosted on an MS IIS webserver. The internet is full of documentation on ASP pages, so here it is just shown how to include persistent variables into an own asp page.

      <!-- #include file = "PersistentVariables.inc"-->
      <%
          ' vbscript code follows here
          ' ...
      %>

  Please note, that it is not the PersistentVariables.vbs file that is being included, but the PersistentVariables.inc file. This is because for asp pages <% and %> needs to be placed around VBScript code.

  You can find this file in the \examples\External\asp folder of the download package. There you will also find a complete example.

  Windows Scripting Files (.wsf)

  These are VBScripts that can be directly called by their filename, not even the .wfs file extension is needed when calling them.

      <package>
      <job id="Example">
      <script language="VBScript" src="PersistentVariables.vbs"/>
      <script language="VBScript">

          ' vbscript code follows here
          ' ...

          WScript.Quit
      </script>
      </job>
      </package>

  You can find the PersistentVariables.vbs file either in the \vbs as also in the \examples\External\vbs folders of the download package. There you will also find a complete example.

  The next step before being able to use any persistent variable is to configure them. While there is no configuration needed if you have installed everything according the suggestion, here it is now necessary to give one important parameter: the database connect string. This is stored into the global variable g_sPersistentVariableConnectString being defined by the persistent variables.

      ' configure the complete db connect string
      g_sPersistentVariableConnectString = _
      	"Provider=sqloledb;" & _
      	"Data Source=SQL_SERVER_NAME;" & _
      	"Initial Catalog=" & PERSISTENT_VARIABLE_DATABASE & ";" & _
      	"User Id=PersistentVariables;" & _
      	"Password=PersistentVariables"

  The Data Source is the sql server machine name, i.e. the SwyxServer machine name.

  The Initial Catalog is the name of the database. If you installed everything according the suggestion this is IpPbxExtensions. This name is defined in the constant PERSISTENT_VARIABLE_DATABASE.

  You most likely can't use integrated security to login to the database, so you need to configure a login with username and password (see 2.1 - Setup Database, Step 5 onward, instead of of Windows authentication you have to use SQL Server authentication). The chosen username and password need to be given as User Id and< Password.

  From now on everything is just like the usage of persistent variables in a call routing script, i.e. like the two first code snippets on this page.

  By Tom Wellige

  - May 14, 2022
  Share
  Share
  Followers 0
  Previous Page 6.5 - Use different database (other than MS SQL Server, e.g. MySQL or Oracle)

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