Get data from DB2 via LotusScript

I have recently made an Lotus Notes Database, where i needed to get some information from DB2.
I this case i also had the issue that only the server could connect to the DB2.

I made an agent that call another agent with the runOnServer method.
Then you can select a document, start a agent that calls a agent on a server, connect to db2, and update the selected document.

Here is an example on how to call db2 in a agent.

Option Public
Option Explicit
Uselsx “NLSXLC”

Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim agent As NotesAgent
Set db = session.CurrentDatabase
Set agent = session.CurrentAgent
Dim doc As NotesDocument
Dim LC_S As New LCSession
Dim LC_Conn As New LCConnection( “DB2”)
Dim LC_FldLst As New LCFieldList(1)
Dim LC_Field As New LCField( LCTYPE_TEXT, 1)
Dim strLCMsg As String
Dim strLCErrorTxt As String
Dim lLCMsgCode As Long
Dim nStatus As Integer
Dim lCount As Long
Dim strSelectStatement As String
Dim strKundenr As String
Dim lTotal As Long
Dim ngl As String
Dim x As string

‘Get doc
Set doc = db.GetDocumentByID(agent.ParameterDocID)

LC_Conn.Database = “SETUP_ALIAS_DB2”
Print “Connect called”

strSelectStatement = “SELECT * FROM DB.Table”
lCount = LC_Conn.Execute( strSelectStatement, LC_FldLst)
Print “Execute Select Statment called”

If lCount <> 0 Then
lCount = LC_Conn.Fetch( LC_FldLst, 1, 1)
‘Select what you want to get from the select
Set LC_Field = LC_FldLst.GetField( 1)
While ( lCount > 0 ) And ( LC_S.Status = LCSUCCESS )
x = x + LC_Field.text( 0)
lCount = LC_Conn.Fetch( LC_FldLst, 1, 1)
lTotal = lTotal + 1

End If
‘ex: write to doc
Call doc.Replaceitemvalue(“field”,x)
Call, False)
End Sub

This entry was posted in Lotus, Tip and tagged , , , , , . Bookmark the permalink.