SNTT - How to find Person Docs without Mail Files
Thursday 24th January, 2008If you have ever experienced a problem with old Person Documents replicating back into your Domino Directory, you know how much of a pain it can be to identify them. Here's a quick LotusScript that will check for the mail file specified in the Person Document and create a document in the database if either the mail file can not be found or if the User ID the agent is ran under doesn't have access to the mail file.
The agent can either flag the Person Document by adding a field to it. This will allow you to create a simple view and select all the Person Documents at once. It also creates a document in the database the agent is ran from so you can go back and manually check each person document.
Sub Initialize
On Error Goto Errorhandler
Dim session As New notessession
Dim db As notesdatabase
Dim dbNAB As notesdatabase
Dim dbmail As notesdatabase
Dim view As notesview
Dim pdoc As notesdocument
Dim logdoc As notesdocument
Dim errcount As Integer
Dim maxcount As Integer
errcount = 0
maxcount = 0
Set db = session.currentdatabase
Set dbNAB = session.GetDatabase("SERVERNAME/HERE","names.nsf")
'Hardcode Server Name and Domino Directory Here
Set pdocview = dbNAB.GetView("People")
'Get Hold on People View from NAB
pdocview.AutoUpdate = False
Set pdoc = pdocview.getfirstdocument()
'Get First Person Document from NAB
Do While Not(pdoc Is Nothing)
'Do While and get Mail Server and Mail File from PDOC
maxcount = maxcount + 1
'>>>>LIMITED TEST RUN - Due to large number of person docs, you can limit how many it initially processes for testing
' If maxcount > 500 Then
' End
' End If
'>>>>LIMITED TEST RUN
MailServer = pdoc.MailServer(0)
MailFile = pdoc.MailFile(0)
Print maxcount & " - " & pdoc.FullName(0)
Set dbmail = session.GetDatabase(MailServer,MailFile,False)
'Try to open mail file specified in PDOC
If dbmail Is Nothing Then
'If Mail File is not valid, creates log document
Set logdoc = db.CreateDocument
logdoc.mailserver = MailServer
logdoc.mailfile = MailFile
logdoc.fullname = pdoc.FullName(0)
logdoc.Form = "MissingMailFile"
Dim nrt As New NotesRichTextItem(logdoc, "Pdoclink")
Call nrt.AppendDocLink(pdoc,"Person Document")
Call logdoc.Save( True, True )
'>>>>>>FLAG PERSON DOCUMENT - OPTIONAL
' pdoc.MissingMailFile = "1"
' Call pdoc.Save(True, True)
'>>>>>>If you want to flag the PDOC in the nab, you can create a view to show all docs with this field and remove them
'>>>>>>FLAG PERSON DOCUMENT - OPTIONAL
End If
Set pdoc = pdocview.getnextdocument(pdoc)
Loop
Exit Sub
ErrorHandler:
'>>>>If you can't access a person's mail file due to ACL rights, that will trigger an error and log it here
errcount = errcount + 1
Set logdoc = db.CreateDocument
logdoc.mailserver = MailServer
logdoc.mailfile = MailFile
logdoc.fullname = pdoc.FullName(0)
logdoc.Form = "AccessMailFile"
Dim nrt2 As New NotesRichTextItem(logdoc, "Pdoclink")
Call nrt2.AppendDocLink(pdoc,"Person Document")
Call logdoc.Save( True, True )
'>>>>Error Trapping will catch first 5 errors and then End the Script
If errcount < 5 Then
Messagebox "Initialize Error " + Cstr(Err) + " : " + Error$ + " on line number " + Cstr(Erl), 16, "CUSTOM AGENT ERROR"
Resume Next
Else
Messagebox "TO MANY ERRORS: Initialize Error " + Cstr(Err) + " : " + Error$ + " on line number " + Cstr(Erl), 16, "CUSTOM AGENT ERROR"
End
End If
End Sub
The agent can either flag the Person Document by adding a field to it. This will allow you to create a simple view and select all the Person Documents at once. It also creates a document in the database the agent is ran from so you can go back and manually check each person document.
Sub Initialize
On Error Goto Errorhandler
Dim session As New notessession
Dim db As notesdatabase
Dim dbNAB As notesdatabase
Dim dbmail As notesdatabase
Dim view As notesview
Dim pdoc As notesdocument
Dim logdoc As notesdocument
Dim errcount As Integer
Dim maxcount As Integer
errcount = 0
maxcount = 0
Set db = session.currentdatabase
Set dbNAB = session.GetDatabase("SERVERNAME/HERE","names.nsf")
'Hardcode Server Name and Domino Directory Here
Set pdocview = dbNAB.GetView("People")
'Get Hold on People View from NAB
pdocview.AutoUpdate = False
Set pdoc = pdocview.getfirstdocument()
'Get First Person Document from NAB
Do While Not(pdoc Is Nothing)
'Do While and get Mail Server and Mail File from PDOC
maxcount = maxcount + 1
'>>>>LIMITED TEST RUN - Due to large number of person docs, you can limit how many it initially processes for testing
' If maxcount > 500 Then
' End
' End If
'>>>>LIMITED TEST RUN
MailServer = pdoc.MailServer(0)
MailFile = pdoc.MailFile(0)
Print maxcount & " - " & pdoc.FullName(0)
Set dbmail = session.GetDatabase(MailServer,MailFile,False)
'Try to open mail file specified in PDOC
If dbmail Is Nothing Then
'If Mail File is not valid, creates log document
Set logdoc = db.CreateDocument
logdoc.mailserver = MailServer
logdoc.mailfile = MailFile
logdoc.fullname = pdoc.FullName(0)
logdoc.Form = "MissingMailFile"
Dim nrt As New NotesRichTextItem(logdoc, "Pdoclink")
Call nrt.AppendDocLink(pdoc,"Person Document")
Call logdoc.Save( True, True )
'>>>>>>FLAG PERSON DOCUMENT - OPTIONAL
' pdoc.MissingMailFile = "1"
' Call pdoc.Save(True, True)
'>>>>>>If you want to flag the PDOC in the nab, you can create a view to show all docs with this field and remove them
'>>>>>>FLAG PERSON DOCUMENT - OPTIONAL
End If
Set pdoc = pdocview.getnextdocument(pdoc)
Loop
Exit Sub
ErrorHandler:
'>>>>If you can't access a person's mail file due to ACL rights, that will trigger an error and log it here
errcount = errcount + 1
Set logdoc = db.CreateDocument
logdoc.mailserver = MailServer
logdoc.mailfile = MailFile
logdoc.fullname = pdoc.FullName(0)
logdoc.Form = "AccessMailFile"
Dim nrt2 As New NotesRichTextItem(logdoc, "Pdoclink")
Call nrt2.AppendDocLink(pdoc,"Person Document")
Call logdoc.Save( True, True )
'>>>>Error Trapping will catch first 5 errors and then End the Script
If errcount < 5 Then
Messagebox "Initialize Error " + Cstr(Err) + " : " + Error$ + " on line number " + Cstr(Erl), 16, "CUSTOM AGENT ERROR"
Resume Next
Else
Messagebox "TO MANY ERRORS: Initialize Error " + Cstr(Err) + " : " + Error$ + " on line number " + Cstr(Erl), 16, "CUSTOM AGENT ERROR"
End
End If
End Sub
Comments [2]