I have two staff databases. The public one has information like name, department, extension number etc. The private one has this same information with additional info like home address. The private one uses readers fields to keep people away from sensitive data.
The problem I have is with keeping the data synchronized.
I want to run an agent to do the following.
a) If a new document is created in the public database, create a second one in the private system.
b) If a document in the public one is deleted then delete the corresponding one from the private database.
c) Synchronize field changes between the two databases.
Here is the code I have so far which almost sorts out c) but not a) and b).
Sub Initialize
'//
On Error Goto ErrorHandler
Dim s As New NotesSession
Dim db As NotesDatabase
Dim publicdb As NotesDatabase
Dim docoll As NotesDocumentCollection
Dim doc As NotesDocument
Dim publicdoc As NotesDocument
Dim lookupview As notesview
Dim counter As Long
Set db = s.currentdatabase
Set publicdb = s.getdatabase(db.server,"EPBStaff.nsf")
If Not(publicdb.isopen) Then
Call publicdb.open("","")
End If
If Not(publicdb.isopen) Then
Msgbox "Unable to open the public staff list database",64,"Error"
Goto OKExit
End If
Set docoll = db.alldocuments
Set lookupview = publicdb.getview("Staff Lookup")
counter = 1
Set doc = docoll.getfirstdocument
While Not(doc Is Nothing)
Set publicdoc = lookupview.getdocumentbykey(doc.getitemvalue("Surname")(0) + " " + doc.getitemvalue("FirstName")(0),False)
If Not(publicdoc Is Nothing) Then
'If Not(doc Is Nothing) Then
Call doc.getfirstitem("StaffNo").copyitemtodocument(publicdoc,"")
Call doc.getfirstitem("Department").copyitemtodocument(publicdoc,"")
Call doc.getfirstitem("JobTitle").copyitemtodocument(publicdoc,"")
Call doc.getfirstitem("LineManager").copyitemtodocument(publicdoc,"")
Call doc.getfirstitem("Extension").copyitemtodocument(publicdoc,"")
Call doc.getfirstitem("Location").copyitemtodocument(publicdoc,"")
Call doc.getfirstitem("MobileNo").copyitemtodocument(publicdoc,"")
Call doc.getfirstitem("ShortCode").copyitemtodocument(publicdoc,"")
Call doc.getfirstitem("DirectDialNo").copyitemtodocument(publicdoc,"")
'Call doc.getfirstitem("Extension").copyitemtodocument(publicdoc,"")
'// add more public fields here
Call publicdoc.save(True,False)
End If
Set doc = docoll.getnextdocument(doc)
Print "Processed " + Cstr(counter) + " documents"
counter = counter + 1
Wend
Goto OKExit
ErrorHandler:
Msgbox "Error (" + Cstr(Err) + "): " + Error + " at line " + Cstr(Erl)
Resume OKExit
OKExit:
End Sub
I hope someone can give me a few pointers where to go next.