Archive for category VBScript

How Do I Run a VBScript OUTSIDE of SalesLogix?

VBScripts CAN be run completely outside of SalesLogix. BUT you do not have access to the SalesLogix Application object.

First you need to be able to make a connection to the (SalesLogix) Provider. The key part here is to pass in a valid (SalesLogix Provider) connection string. I usually create a “.udl” file to do all the heavy lifting here. This is what the contents of a typical “.udl” looks like:

 [oledb]
; Everything after this line is an OLE DB initstring
Provider=SLXOLEDB.1;Password=mypassword;Persist Security Info=True;User ID=admin;Initial Catalog=SALESLOGIXV754DEV;Data Source=GOBIDEV;Extended Properties="PORT=1706;LOG=ON;CASEINSENSITIVEFIND=ON;AUTOINCBATCHSIZE=1;SVRCERT=;"

Now we need to concentrate on the actual script itself. For this example we assume the “.udl” file is called MyConnection.udl and is located at the root of “C” (C:\MyConnection.udl) :

 
Sub Main
  Dim objCon  'SalesLogix Connection Object
  Dim sConnString
  Dim strSQL00
  Dim objMyRS
  Dim blnNewSlxConnection

  'Get a connection to SalesLogix - Cannot use the Application Object in an Agent or outside of SalesLogix
  ' We have to do all of this "outside"
  sConnString= "File Name=C:\MyConnection.udl"

  'Now connect up
  Set objCon = CreateObject("ADODB.Connection")
  If Err.Number <> 0 Then
    blnNewSlxConnection= False
    If IsObject(objCon) Then
      Set objCon = Nothing
    End If
    Err.Clear
    Exit Sub
  Else
    blnNewSlxConnection= True
    objCon.ConnectionString = sConnString
    objCon.Open
  End If

  'Do some work - get data from USERINFO table
  strSQL00 = "SELECT * FROM sysdba.USERINFO"
  Set objMyRs = CreateObject("ADODB.Recordset")
  With objMyRS
    .CursorType = adOpenStatic
    .CursorLocation = adUseClient
    .LockType = adLockBatchOptimistic
    .Open strSQL00, objCon
  End With
  'Now pull in data from USERINFO... and do something with it
  If Not (objMyRS.EOF Or objMyRS.BOF) Then
    'OK
    With objMyRS
      If .RecordCount > 0 Then
        'We have data - now do work...
        While NOT (.EOF or .BOF)
          strUserID = .Fields("USERID").Value
          strLastName = .Fields("LASTNAME").Value
          'Now do some work w/this data
          Call WriteResultsToTraceFile(strUserID,strLastName)
          .MoveNext
        Wend
     Else
       'No data found...
     End If
  End With
  'All done..close shop
  If IsObject(objMyRS) Then
    objMyRS.Close
  End If
  Set objMyRS = Nothing
  If IsObject(objCon) Then
    objCon.Close
  End If
  Set objCon = Nothing

The above is a very simple framework and certainly can be expanded. I have created an include file that contains several of the key functions:

Function NewSlxConnection(ByVal sConnString, objCon)
Function CloseSlxConnection(objCon)
Function GetRecordSetObj(objCon,ByVal strSQL)
Sub CloseRecordSetObj(objRS)
Function ChkError(strInfo)
Function FixQuote(ByVal sSrcLine)
Function ExecuteSQL(objCon, ByVal sSQL00)
Function GetScalarValue(objCon, ByVal sSQL00)
Function GetMultipleScalarValue(objCon,ByVal strSQL, ByVal iRecCount, strValue)
Function GetMultipleValuesFromDB(objCon, ByVal strSQL, strValue)
Function CreateIdFor(objCon, ByVal sTableName)
Function CreateBlockOfIDFor(objCon,ByVal strTableName, ByVal sRecCount, strRecordID)
Function IsEmptyRecordset(ByRef objRS)
Function GetRecordCount(objCon,ByVal TableName, ByVal PKName, ByVal sWhere)

We use this include file in all our external VBScripts and for a small fee we do license it to anyone who is interested (along with some samples/examples).

, , , , ,

Leave a comment