Subject: RE: Retrieve documents from mail db through agent
Actually I’ve got the code from The Sandbox…
Here it is…
%REM
Script to load Calendar entries from a user or group to load into a calendar view to see excactly what the appointments are
This script is made 16/6/2001 by René Romijn
Version 0.1 - Initial database, send it to Notes.net.
Version 0.2 - All the dutch keywords are removed.
Version 1.1 - Version Placed on SandBox
Version 1.2 - Minor bugs resolved (9 points fonts for the mac and some conversion errors)
Version 1.3 - Still deleted some Dutch words
- Changed some major things in the update process, now it don't throw away all the documents but update only if needed
- Thanks must go to Wiebe van Bruggen, he had some nice tricks!
- Check on type of document to included
Version 1.3.1 - Wrong point Userview.GetNextDocument( Userdoc ).
- Don't use the db.Search formula, coz the documentcollection is not useable in this kind of action
- Use BusyName also in the key, if there is an meeting then there where multiple documents with the same UniversalID
this script is only to be used on mail files that are reside on the same server
Tell the agent that he has to run several times a day and on the server where the mail files resides
If you have comments: r.romijn@zonnet.nl
%ENDREM
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim Userdb As NotesDatabase
Dim Userview As NotesView
Dim Userdoc As NotesDocument
Dim CompareDoc As NotesDocumentCollection
Dim view As NotesView
Dim CompareView As NotesView
Dim doc As NotesDocument
Dim nxtdoc As NotesDocument
Dim Profiledoc As NotesDocument
Dim TestApp(200) As String 'Assuming that nobody has more then 200 (different!) repeating or overlapping in day's appointments
Dim vc As NotesViewEntryCollection
Print "Import mail entries start: " & Trim( Str$( Now ) )
Set db = session.CurrentDatabase
'Get the profile doc where the config is
Set Profiledoc = db.GetProfileDocument("Settings")
Error_Status="0"
'Setting the date range to look for in the user mail databases
Min=Profiledoc.min
Min=Min(0)
Max=Profiledoc.max
Max=Max(0)
DateMin=Cdbl(Date())-Min
DateMax=Cdbl(Date())+Max
Type_Included=Profiledoc.Type_Included
Set view = db.GetView("($Calendar)")
'Set on all the documents a flag, if in the end the flag is still "1" then delete the document
'Check also for documents that fall out the range and delete those documents
Set CompareView = db.GetView("Entries")
Set doc=CompareView.GetFirstDocument
While Not (doc Is Nothing)
DateRange=doc.CalendarDateTime
Value=Datevalue(DateRange(0))
DateRange=Cdbl(Value)
If DateRange < DateMin Then
Call doc.Remove(True)
Set doc=CompareView.GetFirstDocument
Else
doc.refresh_calendar="1"
Call doc.save(True,True)
Set doc=CompareView.GetNextDocument(doc)
End If
Wend
Forall i In Profiledoc.mailfiles
'Clear the arry that is needed for the repeating appointments
Erase TestApp
TestAppCounter=1
Servername=Strleft(i,":") 'Don't use it yet
Mailfile=Strright(i,":") 'This can only work if a server can reach another server from an agent
On Error Goto OpenDatabase
Print "Opening: " & Mailfile
Set Userdb = New NotesDatabase( Servername, Mailfile )
Set Userview = Userdb.GetView( "($Calendar)" )
Set Userdoc = Userview.GetFirstDocument
On Error Goto GeneralError
While Not ( Userdoc Is Nothing )
DatumRange=Userdoc.CalendarDateTime
Value=Datevalue(DatumRange(0))
DatumRange=Cdbl(Value)
If DatumRange > DateMin Then
If DatumRange < DateMax Then
If Userdoc.form(0)="Task" Then
'Skip the task forms, whe don't want to know what someone is doing.
Else
Forall k In Type_Included
If Userdoc.AppointmentType(0)=k Then
IsIncluded="1"
Exit Forall
End If
End Forall
If IsIncluded="1" Then
'Look if we already have a document of this entry
Owner=Userdoc.GetItemValue("$BusyName")
CompareUID=Userdoc.UniversalID + Owner(0)
Set CompareDoc = CompareView.GetAllDocumentsByKey(CompareUID, True)
OldDoc=0
If CompareDoc.Count>0 Then
OldDoc=1
End If
DateRange=Userdoc.CalendarDateTime
Value=Datevalue(DateRange(0))
DateRange=Cdbl(Value)
'Look if we have to deal with repeating appointments, they has to be copied in a different way,
'coz if you copy them all, they appear multiple times in the calendar view
NumberOfRepeatingDocs=Evaluate("@Elements(CalendarDateTime)",Userdoc)
If NumberOfRepeatingDocs(0)=1 Then
If OldDoc=1 Then
Set doc = CompareDoc.GetFirstDocument
'Look if there are changes in the original document
If doc.LastModifiedInCalendar(0) = Userdoc.LastModified Then
'Do Nothing
Else
'there are changes, just copy all the fields rather then checking all the fields!
Call Userdoc.CopyAllItems( doc, True )
doc.LastModifiedInCalendar = Userdoc.LastModified
Owner=Userdoc.GetItemValue("$BusyName")
doc.originalid = Userdoc.UniversalID+Owner(0)
End If
Else
Set doc = New NotesDocument( db )
Call Userdoc.CopyAllItems( doc, True )
doc.LastModifiedInCalendar = Userdoc.LastModified
Owner=Userdoc.GetItemValue("$BusyName")
doc.originalid = Userdoc.UniversalID+Owner(0)
End If
doc.refresh_calendar="0"
'Check to see if we copied a private appointment
If Userdoc.orgconfidential(0)="1" Then
'Just change the subject to private appointment
doc.subject="Private appointment"
End If
Call doc.Save( True, True )
Else
'Well, we have an repeating appointment, check if we already processed the document in early stages
UniqueID=Userdoc.UniversalID
IsProcessed=0
For j=1 To TestAppCounter
If TestApp(j)=UniqueID Then
IsProcessed=1
Exit For
End If
Next
If IsProcessed=0 Then
'We store the Appointment Unique ID in an array coz we want this document only one time in the view
TestApp(TestAppCounter)=UniqueID
TestAppCounter=TestAppCounter+1
FirstTime=0
Forall dates In Userdoc.CalendarDateTime
If OldDoc=1 Then
If FirstTime=0 Then
Set doc = CompareDoc.GetFirstDocument
FirstTime=1
Else
Set doc = CompareDoc.GetNextDocument(doc)
End If
If doc.LastModifiedInCalendar(0) = Userdoc.LastModified Then
'Do Nothing
Else
'there are changes, just copy all the fields rather then checking all the fields!
Call Userdoc.CopyAllItems( doc, True )
doc.CalendarDateTime=dates 'Fool Notes that the start date is different
doc.LastModifiedInCalendar = Userdoc.LastModified
Owner=Userdoc.GetItemValue("$BusyName")
doc.originalid = Userdoc.UniversalID+Owner(0)
End If
Else
Set doc = New NotesDocument( db )
Call Userdoc.CopyAllItems( doc, True ) 'Just copy all items
doc.CalendarDateTime=dates 'Fool Notes that the start date is different
Owner=Userdoc.GetItemValue("$BusyName")
doc.originalid = Userdoc.UniversalID+Owner(0)
If Userdoc.orgconfidential(0)="1" Then
'Just change the subject to private appointment
doc.subject="Private appointment"
End If
End If
doc.refresh_calendar="0"
Call doc.Save( True, True )
End Forall
End If
End If
End If
End If
End If
End If
IsIncluded="0"
' Get the next user document
Set Userdoc = Userview.GetNextDocument( Userdoc ) ' Get the next user document
Wend
OpenDatabaseResume:
End Forall
If Error_Status="0" Then
'This view shows the entries who has been deleted in the userdatabase, the flag that is set in the beginning is still "1" so delete it
Set view = db.GetView("Deleted Entries")
Set vc = view.AllEntries
Call vc.RemoveAll( True )
End If
Print "Import mail entries stop: " & Trim( Str$( Now ) )
Exit Sub
GeneralError:
Print "General Failure"
Resume Next
OpenDatabase:
Print "Database from " + Mailfile + " cannot be opened!"
Error_Status="1"
Goto OpenDatabaseResume
End Sub