'SampleAndiApiCall: Option Public Option Explicit Sub Initialize Dim session As New NotesSession Dim andiDB As NotesDatabase Dim agent As NotesAgent Dim agentRunStatus As Integer Dim reportDoc As NotesDocument Dim strNoteID As String Dim agentLog As NotesLog ' path to Andi database Const ANDI_DB_PATH = "Andi/Andi.nsf" ' name of the Andi API agent Const ANDI_AGENT = "(AndiApiAgent)" ' Set ReportLog Set agentLog = New NotesLog("Andi API Call") agentLog.OpenAgentLog On Error Goto ErrProcess ' open the Andi db (must reside on local server) Set andiDB=session.GetDatabase("", ANDI_DB_PATH) If Not AndiDB.IsOpen Then Goto ErrAndiDB ' get a handle to the Andi api agent Set agent=AndiDB.GetAgent(ANDI_AGENT) If agent Is Nothing Then Goto ErrGetAgent ' create a new Report doc to hold the parameters Set reportDoc=New NotesDocument(andiDB) With reportDoc ' Activity identification: parameters must match those defined in Activity Document .reqActivityType = "Import" ' "Import" or "Export" ' .reqActivityNoteID = "A4A" 'or ' .reqActivityUnid = "78AF0EF83560F3ABC1256D2000405038" ' 32-byte entry 'or .reqActivityName = "1.1. RefTable from text file" ' For Import: .reqImportSourceType = "$FILE" ' valid entries: "$FILE", "$XML", "$ODBC", "$NOTESDB" .reqOperationType = "$UC" ' valid entries: "$U", "$C", "$UC", "$D" 'or ' For Export: ' .reqExportDestType = "$FILE" ' valid entries: "$FILE", "$HTML" , "$XML", "$ODBC" ' overwrite parameters: must be authorized ' Record range .paramStartRecord = "1" .paramMaxRecords = "2" ' For Import: .paramImportSource = " D:\AndiData\Orders.txt" .paramImportDestination = "Andi\testData2.nsf" ' For Export: ' .paramExportSource = "D:\Abc\Test\Dest.nsf" ' .paramExportDestination = "D:\ABC\Test\TestExportTXT2.txt" ' For ODBC: ' .paramODBCUserID= "User1" ' .paramODBCPassword = "abcde" ' .paramODBCQuery = {SELECT F1, F2, F3 FROM table01 WHERE F4='yes'} ' .paramODBCTable = "table_" & Format ( Today, "yymmdd") ' For NotesDB source: ' .paramSelectionView = "ByNum" ' .paramSelectionFormula = {Form="Customer" & Status="1"} ' Other parameters .paramScheduleInfo = "Sample call from " & session.CurrentDatabase.FilePath & " - agent: " & session.CurrentAgent.Name .paramScheduleOriginator = session.EffectiveUserName End With ' save parameters reportDoc.Save True, False ' hold the NoteID of the report doc strNoteID = reportDoc.NoteID ' release reportDoc object Set reportDoc = Nothing ' execute the Andi agent, passing it doc’s NoteID agentRunStatus = agent.Run(strNoteID) If agentRunStatus <> 0 Then Goto ErrAgentRun ' get the report doc back Set reportDoc=AndiDB.GetDocumentByID(strNoteID) If reportDoc Is Nothing Then Goto ErrReportDoc If Val ( reportDoc.ApiReturnCode(0)) > 255 Then agentLog.LogAction "Api run OK" ' Report to agent log Call Report ( reportDoc, agentLog) Exit Sub '************ Error routines ************ ErrProcess: agentLog.LogError Err, "Line: " & Erl & " - " & Error Exit Sub ErrAndiDB: agentLog.LogAction "Error: Unable to get ANDI database" Exit Sub ErrGetAgent: agentLog.LogAction "Error: Unable to get ANDI agent" Exit Sub ErrAgentRun: agentLog.LogAction "Error: Fail to run ANDI agent" Exit Sub ErrReportDoc: agentLog.LogAction "Error: Unable to get Report Document" Exit Sub End Sub Sub Report( reportDoc As NotesDocument, agentLog As NotesLog) ' report to agent log ' only fields of interrest are reported here ' some other fields might exist in the document but are not officially supported Const FIELD_NAMES = { ApiReturnCode, StartTime, EndTime, StartRecord, MaxRecords, IsError, ExceptionError, isParamOverwritten, OverwrittenParam, AuthorNames, ReaderNames, ImportSourceType, ImportDestType, ImportSource, ImportDestination, OperationType, CountRead, CountAdd, CountUpdate, CountDelete, CountReject1, CountReject2, CountReject3, CountReject4, CountReject, CountNoHit, CountMatch, CountHit, JoinNumber, CountJoinHit_1, CountJoinHit_2, CountJoinHit_3, CountJoinHit_4, CountJoinHit_5, CountJoinHit_6, CountJoinHit_7, CountJoinHit_8, CountJoinHit_9, CountJoinHit_10, ExportSourceType, ExportDestType, ExportSource, ExportDestination, ODBCUserID, ODBCTable} Dim vFields As Variant Dim sValue As String vFields = Fulltrim ( Split ( FIELD_NAMES, ",")) ' R6 only ' vFields = Evaluate ({@Trim(@Explode("} & FIELD_NAMES &{" ; ","))}) ' pre R6 Forall x In vFields sValue = reportDoc.GetItemValue (x)(0) If sValue <> "" Then agentLog.LogAction x & " = " & sValue End If End Forall ' special case with 'Log' field wich is multi-valued Forall x In reportDoc.Log agentLog.LogAction "Log = " & x End Forall End Sub