Checking for new documents in a database from another database using lotusscript

Hi

I am trying to do something which might seem to make no sense. But I want to get this to work anyway.

I want to find out from 1 database if there are any new documents in another database. Is this technically possible in LotusScript?

Regards

Subject: Checking for new documents in a database from another database using lotusscript

It depends on what You define as “new document”. If it is simply to check for any documents with a statusfield with status ‘New’, then it is very possible.

If You need to check the date/time when the document is added, then it gets a little bit more tricky - but still very doable. Just take the last date/time the script was run and search and find all documents added after that date/time.

Subject: RE: Checking for new documents in a database from another database using lotusscript

You could also have an agent running in the other database, updating your database whenever a new document is created.

As Kenneth suggests, there’s some important detail missing from your question. What do you mean by “new,” and do you need access to the new documents, or do you just need to know whether or not documents have been created?

Subject: RE: Checking for new documents in a database from another database using lotusscript

Hi

With new documents I mean documents that are newly created in the database. I know that I can place an agent in the other database to react on all new and modofied documents. But in my particular case it would be nice if I can do it this way. I need to read certain fields from the new documents.

Regards

Subject: RE: Checking for new documents in a database from another database using lotusscript

Here is a script that finds all documents that is new or modified after a specified date (in this case Nov 1st 2003):

Dim nSess As New NotesSession

Dim nDb As NotesDatabase

Dim nDate As NotesDateTime

Dim nColl As NotesDocumentCollection



Set nDb = New NotesDatabase("", "lsexamples.nsf")

Set nDate = New NotesDateTime("2003-11-01 08:00:00")

Set nColl = nDb.Search(|Form="Help"|,nDate,0)



If nColl.Count <> 0 Then

	Msgbox nColl.Count & " documents found!", 64, "New documents"

Else

	Msgbox "No documents found!", 48, "New Documents"

End If

If You only need NEW documents (and not modified), then You have to loop through the collection and examine each doc to see if it is modified or created past the specified date…

Subject: RE: Checking for new documents in a database from another database using lotusscript

Newly created since when? You’ll probably want to go with Kenneth’s suggestion of recording a date/time somewhere in your database and using that to check documents in the other database.

Subject: RE: Checking for new documents in a database from another database using lotusscript

You seem to be trying to very clearly state that you would like an agent trigger called “When docs are added or modified in another db.” This, of course, cannot be done. The closest you can come is to run a scheduled agent which runs at the most frequent period allowed (every 5 minutes) that checks for new docs.

Subject: Checking for new documents in a database from another database using lotusscript

Here’s an example that might help.

Dim session As New notessession

Dim db As notesdatabase

Dim db2 As New notesdatabase("Server1", "develop/test stuff2.nsf")   'server name on notes/no server name on web

Dim view As notesview

Dim dc As notesdocumentcollection

Dim doc, NextDoc As notesdocument

Dim item As notesitem

Dim x, y As String

y = "test" 'if the document contains this value,  you are going to delete the document



Set db = session.currentdatabase



Set db2 = New notesdatabase("Server1", "develop/test stuff2.nsf")

Set view = db2.getview("All Docs") ' this is the view containing the documents you want to search



Set doc = view.getfirstdocument



While Not (doc Is Nothing)

	Set NextDoc = view.getnextdocument(doc)

	Set item = doc.getfirstitem("test") 'this is the field holding the item, i.e., SUBJECT

	If item.values(0) = "test" Then 'add again, check for itemyou want to delete

		

		x = item.values(0)

		If x = y Then

			Call doc.Remove(True)

		End If

		

		Set doc= NextDoc

	End If	

Wend



Call view.refresh 'refresh the view