Issue:
You have an application with a profile document. (e.g. mail file) You want to know what fields are in the document in the back-end.
Solution:
To load the profile read only so no changes occur to it, you can do the following:
Dim w As New NotesUIWorkspace
Dim db as NotesDatabase
Dim doc as NotesDocument
Set db = s.CurrentDatabase
Set doc = db.GetProfileDocument("ProfileDocName" )
Call w.EditDocument( False, doc, True )
Mail File Preference/Profile Fields:
Profile name is: CalendarProfile
Owner
- owner of the mail file.
PublicRead = "1"
- ACL should be set so that anyone can see calendar entries in this mail file
ReadCalendar
- Names field, list of names of who can read the calendar when not public
PublicWrite ="1"
- ACL should be set so that anyone can create/edit/see calendar entries
WriteCalendar
- Names field, list of names of who can read/create/edit the calendar when not public
ReadMail
- Names field, list of names of who can read/see mail AND read calendar entries
WriteMail
- Names field, list of names of who can read/create (send) mail AND read calendar entries
EditMail
- Names field, list of names of who can read/create (send)/edit mail AND any other type of document in the mail file
DeleteMail
- Names field, list of names of who can delete mail and calendar entries if they are in the WriteMail or EditMail fields.
OtherUsers
- Names field, contains designer or manager ACL entries.
AllowBusyAccess
- Names field, list of names who can see when this user/mail file is free. (calendar readers/creators/editors already have access)
Sample Code to Recreate a Lost Mailfile Using Person Doc:
Option Public
Option Declare
Sub Initialize
Dim w As New NotesUIWorkspace
Dim s As New NotesSession
Dim db As NotesDatabase ' names.nsf
Dim pDoc As NotesDocument ' person doc
Dim pCol As NotesDocumentCollection ' selected docs in view
Dim userlevel As Integer ' desired acl level for mailfile owner/user
Dim templatenm As String ' filename of template
On Error Goto ErrorHandler
' setup
userlevel = 5
templatenm = "iNotes5.ntf"
Set db = s.CurrentDatabase
Set pCol = db.UnprocessedDocuments
Set pDoc = pCol.GetFirstDocument
While Not (pDoc Is Nothing)
' loop through person docs, creating new mail files
Call ProcessPerson(s, db, pDoc, userlevel, templatenm)
Set pDoc = pCol.GetNextDocument(pDoc)
Wend
Print "Done"
Exit Sub
ErrorHandler:
Print "(Initialize) Error: " & Cstr(Err) & " " & Error$ & ", on line: " & Cstr(Erl) & "."
Exit Sub
End Sub
Function ProcessPerson(s As NotesSession, db As NotesDatabase, pDoc As Notesdocument, userlevel As Integer, templatenm As String) As Integer
Dim templateDb As NotesDatabase ' template for mail
Dim mailsvr As String
Dim mailpath As String
Dim mailuser As String
Dim mailNm As NotesName
Dim mDb As NotesDatabase ' new mail file
Dim acl As NotesACL ' new mail file acl
Dim aclEntry As NotesACLEntry ' new / updated acl entry
Dim profileDoc As NotesDocument ' preferences profile w/ owner
On Error Goto FErrorHandler
' get mail values from person doc
mailsvr = pDoc.MailServer(0)
mailpath = pDoc.MailFile(0)
mailuser = pDoc.FullName(0)
Set mailNm = New NotesName(mailuser)
Set mDb = s.GetDatabase(mailsvr, mailpath, False)
If Not (mDb Is Nothing) Then
ProcessPerson =1
Exit Function
End If
' get template
Set templateDb = s.GetDatabase(mailsvr, templatenm, False)
If (templateDb Is Nothing) Then
' try original/this server
Set templateDb = s.GetDatabase(db.Server, templatenm, False)
If (templateDb Is Nothing) Then
' cancel
Print "Template: " & templatenm & " not loaded. Aborted."
ProcessPerson = 0
Exit Function
End If
End If
' create it
Set mDb = templateDb.CreateFromTemplate( mailsvr, mailpath, True )
If (mDb Is Nothing) Then
' error
ProcessPerson = 0
Print "(ProcessPerson) Unable to create mailfile: " & mailsvr & ", " & mailpath & "."
Exit Function
End If
mDb.Title = mailNm.Common
' sleep to give time to create
Sleep 2
' update acl
Set acl = mDb.ACL
' do home server
Set aclEntry = acl.GetEntry( mailsvr )
If (aclEntry Is Nothing) Then
' create it
Set aclEntry = New NotesACLEntry( acl, mailsvr, 6 )
aclEntry.CanDeleteDocuments = True
aclEntry.IsServer = True
aclEntry.IsAdminServer = True
Else
' make sure mgr
If (aclEntry.Level < 6) Then
aclEntry.Level = 6
End If
aclEntry.CanDeleteDocuments = True
aclEntry.IsServer = True
aclEntry.IsAdminServer = True
End If
' do LocalDomainAdmins
Set aclEntry = acl.GetEntry( "LocalDomainAdmins" )
If (aclEntry Is Nothing) Then
' create it
Set aclEntry = New NotesACLEntry( acl, "LocalDomainAdmins", 6 )
aclEntry.CanDeleteDocuments = True
Else
' make sure mgr
If (aclEntry.Level < 6) Then
aclEntry.Level = 6
End If
aclEntry.CanDeleteDocuments = True
End If
' do LocalDomainServers
Set aclEntry = acl.GetEntry( "LocalDomainServers" )
If (aclEntry Is Nothing) Then
' create it
Set aclEntry = New NotesACLEntry( acl, "LocalDomainServers", 6 )
aclEntry.CanDeleteDocuments = True
Else
' make sure mgr
If (aclEntry.Level < 6) Then
aclEntry.Level = 6
End If
aclEntry.CanDeleteDocuments = True
End If
' set owner
Set aclEntry = acl.GetEntry( mailNm.Canonical )
If (aclEntry Is Nothing) Then
' create it
Set aclEntry = New NotesACLEntry( acl, mailNm.Canonical , userlevel )
aclEntry.CanDeleteDocuments = True
aclEntry.IsPerson = True
Else
' make sure right user access level
If (aclEntry.Level < userlevel) Then
aclEntry.Level = userlevel
End If
aclEntry.CanDeleteDocuments = True
aclEntry.IsPerson = True
End If
' save acl
Call acl.Save()
' update owner
Set profileDoc = mDb.GetProfileDocument("CalendarProfile" )
If Not (profileDoc Is Nothing) Then
Call profileDoc.ReplaceItemValue("Owner", mailNm.Canonical)
Call profileDoc.Save(True,False)
Else
Print "Unable to update owner for mailfile: " & mailpath & "."
End If
' done
ProcessPerson = 1
FExit:
Exit Function
FErrorHandler:
Print "(Initialize) Error: " & Cstr(Err) & " " & Error$ & ", on line: " & Cstr(Erl) & "."
Resume FExit
End Function
Code to Delete the Calendar Profile If Corrupt (e.g. 6.5 to 8.5 upgrade):
Dim s As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Set db=s.CurrentDatabase
Set doc=db.GetProfileDocument("CalendarProfile")
Call doc.Remove(True) ' force delete
If doc Is Nothing Then
MsgBox "Profile document has been successfully removed", ,"Success"
Else
MsgBox "Profile Document is NOT Removed",48, "Failed"
End if
previous page
|