Notes C Api to get Last modified in replica time

Hi,

We have a small problem. A scheduled agent is trying to get collection of docs modified for a particular date range eg - 01 Jan to 05 Jan.

Once it gets all the docs, it sorts it by date. To get the modified date in this replica we are using C api calls as below.


With doc.ParentDatabase

db = String$(1024," ")

OSPathNetConstruct 0,.server,.filePath,db

End With

Dim hDb As Long

NSFDbOpen db,hDb

If hDb = 0 Then Exit Function

Dim hNt As Long

Dim t(1) As Long

NSFNoteOpenExt hDb,Clng(“&H” & doc.NoteID),0,hNt

If Not hNt = 0 Then

NSFNoteGetInfo hNt,4,t(0)

NSFNoteClose hNT

s = Space(80)

Dim ndt As New NotesDateTime(t(0))

ConvertTIMEDATEToText 0,0,t(0),s,80,ns

Set rc = New NotesDateTime(Left$(s$,ns))

End If

NSFDbClose hDb

The NSFNoteGetInfo hNt,4,t(0) should return a numeric value which is converted into date time value.

This code in a scheduled agent does not give the date time value. Same when done through manual agent returns proper values. The agent properties are not changed at all.

Any ideas what could be the reason?

Subject: Try this

Try this - this runs in a schduled agent:

Type HIST_ENTRY

RepTime As String

ServerName As String

FileName As String

Direction As String

End Type

Type TIMEDATE

Innards1 As Long

Innards2 As Long

End Type

Type REPLHIST_SUMMARY

ReplicationTime As TIMEDATE

AccessLevel As Integer

AccessFlags As Integer

Direction As Integer

ServerNameOffset As Long

ServerNameLength As Integer

FileNameLength As Integer

Spare1 As Long

Spare2 As Long

End Type

Declare Sub OSPathNetConstruct Lib “nnotes” (Byval portName$, Byval ServerName$, Byval FileName$, Byval retPathName$)

Declare Function NSFDbGetReplHistorySummary% Lib “nnotes” (Byval hDb&, Byval Flags&, rethSummary&, retNumEntries&)

Declare Function NSFDbOpen% Lib “nnotes” (Byval PathName$, hDB&)

Declare Function NSFDbClose% Lib “nnotes” (Byval hDB&)

Declare Function OSMemFree% Lib “nnotes” (Byval Handle&)

Declare Function OSLockObject& Lib “nnotes” (Byval nHandle&)

Declare Function OSUnlockObject% Lib “nnotes” (Byval nHandle&)

Declare Function ConvertTIMEDATEToText% Lib “nnotes” (Byval intFormat&, Byval TextFormat&, InputTime As TIMEDATE, Byval retTextBuffer$, Byval TextBufferLength%, retTextLength%)

Declare Function OSLoadString% Lib “nnotes” (Byval hModule&, Byval StringCode%, Byval retBuffer$, BufferLength%)

Declare Sub CopyMemory Lib “kernel32” Alias “RtlMoveMemory” (pDest As REPLHIST_SUMMARY, Byval pSource&, Byval dwLength&)

Declare Sub CopyMemoryStr Lib “kernel32” Alias “RtlMoveMemory” (Byval pDest$, Byval pSource&, Byval dwLength&)

Dim sList() As String

Dim nCt%, nReturn%

Dim lEntries&

Dim sMsg$, sBuffer$

Function GetReplHistory(db As NotesDatabase, sList() As String, lEntries&) As Integer

’ This function returns the replication history for a database in the same format as you would see

’ by selecting “File - Replication - History” (and clicking Server name radio button) in the Notes R5 client.

’ The function has (3) parameters:

’ 1. db (NotesDatabase) - [Input] Indicates the database you wish to open

’ 2. sList (String array) - [Output] Returns array of strings that will hold the formatted history

’ 3. lEntries (Long) - [Output] Returns the number of entries returned from the NSFDbGetReplHistorySummary call

’ The function itself returns an integer. If no errors are found, it returns a 0. Otherwise, it returns the error

’ code returned by the Notes API.

Dim hDb&, hLock&, hSummary&

Dim nLoop%, cbReturn%, nPos%, nRetCode%

Dim sPath$, sHold$, sRepTime$, sTemp$, sServer$, sFileName$

Dim summary As REPLHIST_SUMMARY

Dim entry() As HIST_ENTRY

Dim nm As NotesName



 ' what to return if no errors are found

GetReplHistory=0 



 ' prepare a string for API call

sPath$=Space(MAXPATH)



 ' create an API-friendly path to the db and open it

OSPathNetConstruct "", db.Server, db.FilePath, sPath$

nRetCode%=NSFDbOpen(sPath$, hDb&)



If nRetCode% <> 0 Then

	GetReplHistory = nRetCode%

Else

      ' get handle to replication history summary (sorted by server name) 

	nRetCode%=NSFDbGetReplHistorySummary(hDb&, 0, hSummary&, lEntries&) 

	

	If nRetCode% <> 0 Then

		GetReplHistory = nRetCode% 

	Else

		

           ' process only if there are entries in the history summary

		If lEntries& > 0 Then

			Redim entry(lEntries& - 1)

			sRepTime$=Space(MAXALPHATIMEDATE + 1) 

			

                ' lock down the handle to the history summary so we can get at the data

			hLock&=OSLockObject(hSummary&) 

			

			For nLoop%=0 To lEntries&-1

                     ' extract replication history by looping over the array of REPLHIST_SUMMARY structs

				CopyMemory summary, hLock&, Lenb(summary)

				

                     ' convert Notes TIMEDATE to a legible text string for replication time

				ConvertTIMEDATEToText 0, 0, summary.ReplicationTime, sRepTime$, MAXALPHATIMEDATE, cbReturn%

				entry(nLoop%).RepTime=Left$(sRepTime$, cbReturn%) 

				

                     ' get replication direction

				Select Case summary.Direction

				Case DIRECTION_NEVER

					entry(nLoop%).Direction="Never Received" 

					

				Case DIRECTION_SEND

					entry(nLoop%).Direction="Send" 

					

				Case DIRECTION_RECEIVE

					entry(nLoop%).Direction="Receive" 

					

				End Select 

				

                     ' advance offset to next REPLHIST_SUMMARY struct

				hLock&=hLock&+Lenb(summary)

			Next

			

                ' as server/filenames are not part of the REPLHIST_SUMMARY struct, but rather at the end of the

                ' array of these structs, we'll need to grab this info one char at a time (for each entry we find) in the

                ' format: CN=ServerA/O=OrgA!!myfile.nsf/0CN=ServerB/O=OrgAA!!myfile.nsf/0, etc.

			sHold$=""

			sTemp$=String$(1, 0) 

			nLoop%=0 

			Do While nLoop% < lEntries&

				CopyMemoryStr sTemp$, hLock&, 1

				If sTemp$ = Chr$(0) Then

                          ' parse out server and filename

					nPos%=Instr(1, sHold$, "!!")

					entry(nLoop%).ServerName=Left$(sHold$, nPos%-1)

					entry(nLoop%).FileName=Right$(sHold$, Len(sHold$)-nPos%-1)

					sHold$=""

					nLoop%=nLoop% + 1

				Else

                          ' build the string one char at a time

					sHold$=sHold$ & sTemp$

				End If

				

                     ' advance the offset

				hLock& = hLock& + 1

			Loop

			

                ' release the lock on the history summary handle once we're done with it

			OSUnlockObject(hSummary&)

			

			Redim sList(lEntries&-1)

			For nLoop%=0 To lEntries&-1

                     ' populate the array of entries to return to the caller

				Set nm=New NotesName(entry(nLoop%).ServerName)

				sList(nLoop%)=Trim$(nm.Abbreviated & " " & entry(nLoop%).FileName & " " & entry(nLoop%).RepTime & " (" & entry(nLoop%).Direction & ")")

			Next

			

		End If

		

	End If

	

      ' free any open handles to the history summary and/or the db

	If hSummary& <> 0 Then OSMemFree hSummary& 

	If hDb& <> 0 Then NSFDbClose hDb&

End If

End Function