{"id":150,"date":"2012-05-10T11:09:22","date_gmt":"2012-05-10T09:09:22","guid":{"rendered":"http:\/\/teske.dk\/?p=150"},"modified":"2012-05-10T11:09:22","modified_gmt":"2012-05-10T09:09:22","slug":"get-data-from-db2-via-lotusscript","status":"publish","type":"post","link":"http:\/\/teske.dk\/?p=150","title":{"rendered":"Get data from DB2 via LotusScript"},"content":{"rendered":"<p>I have recently made an Lotus Notes Database, where i needed to get some information from DB2.<br \/>\nI this case i also had the issue that only the server could connect to the DB2.<\/p>\n<p>I made an agent that call another agent with the runOnServer method.<br \/>\nThen you can select a document, start a agent that calls a agent on a server, connect to db2, and update the selected document.<\/p>\n<p>Here is an example on how to call db2 in a agent.<\/p>\n<p>Option Public<br \/>\nOption Explicit<br \/>\nUselsx &#8220;NLSXLC&#8221;<\/p>\n<p>Sub Initialize<br \/>\n\tDim session As New NotesSession<br \/>\n\tDim db As NotesDatabase<br \/>\n\tDim agent As NotesAgent<br \/>\n\tSet db = session.CurrentDatabase<br \/>\n\tSet agent = session.CurrentAgent<br \/>\n\tDim doc As NotesDocument<br \/>\n\tDim LC_S As New LCSession<br \/>\n\tDim LC_Conn As New LCConnection( &#8220;DB2&#8221;)<br \/>\n\tDim LC_FldLst As New LCFieldList(1)<br \/>\n\tDim LC_Field As New LCField( LCTYPE_TEXT, 1)<br \/>\n\tDim strLCMsg As String<br \/>\n\tDim strLCErrorTxt As String<br \/>\n\tDim lLCMsgCode As Long<br \/>\n\tDim nStatus As Integer<br \/>\n\tDim lCount As Long<br \/>\n\tDim strSelectStatement As String<br \/>\n\tDim strKundenr As String<br \/>\n\tDim lTotal As Long<br \/>\n\tDim ngl As String<br \/>\n\tDim x As string<\/p>\n<p>\t&#8216;Get doc<br \/>\n\tSet doc = db.GetDocumentByID(agent.ParameterDocID)<\/p>\n<p>\tLC_Conn.Userid = &#8220;SETUP_ALIAS_USER&#8221;<br \/>\n\tLC_Conn.Password = &#8220;SETUP_ALIAS_PASSWORD&#8221;<br \/>\n\tLC_Conn.Database = &#8220;SETUP_ALIAS_DB2&#8221;<br \/>\n\tLC_Conn.Disconnect<br \/>\n\tLC_S.ClearStatus<br \/>\n\tLC_Conn.Connect<br \/>\n\tPrint &#8220;Connect called&#8221;<\/p>\n<p>\tstrSelectStatement = &#8220;SELECT * FROM DB.Table&#8221;<br \/>\n\tlCount = LC_Conn.Execute( strSelectStatement, LC_FldLst)<br \/>\n\tPrint &#8220;Execute Select Statment called&#8221;<\/p>\n<p>\tIf lCount <> 0 Then<br \/>\n\t\tlCount = LC_Conn.Fetch( LC_FldLst, 1, 1)<br \/>\n\t\t&#8216;Select what you want to get from the select<br \/>\n\t\tSet LC_Field = LC_FldLst.GetField( 1)<br \/>\n\t\tWhile ( lCount > 0 ) And ( LC_S.Status = LCSUCCESS )<br \/>\n\t\t\tx = x + LC_Field.text( 0)<br \/>\n\t\t\tlCount = LC_Conn.Fetch( LC_FldLst, 1, 1)<br \/>\n\t\t\tlTotal = lTotal + 1<\/p>\n<p>\t\tWend<br \/>\n\tEnd If<br \/>\n\tLC_Conn.Disconnect<br \/>\n\tLC_S.ClearStatus<br \/>\n\t&#8216;ex: write to doc<br \/>\n\tCall doc.Replaceitemvalue(&#8220;field&#8221;,x)<br \/>\n\tCall doc.save(True, False)<br \/>\nEnd Sub<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <a href=\"http:\/\/teske.dk\/?p=150\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[74,77],"tags":[43,3,31,24,44,4],"_links":{"self":[{"href":"http:\/\/teske.dk\/index.php?rest_route=\/wp\/v2\/posts\/150"}],"collection":[{"href":"http:\/\/teske.dk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/teske.dk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/teske.dk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/teske.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=150"}],"version-history":[{"count":1,"href":"http:\/\/teske.dk\/index.php?rest_route=\/wp\/v2\/posts\/150\/revisions"}],"predecessor-version":[{"id":151,"href":"http:\/\/teske.dk\/index.php?rest_route=\/wp\/v2\/posts\/150\/revisions\/151"}],"wp:attachment":[{"href":"http:\/\/teske.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/teske.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=150"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/teske.dk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}