After you move a user from one server to another or if you change the users mail file name (after a user rename, or database corruption), the user's personal address book never gets updated. Sometimes you forget to send a user a button, or call the user, to have their personal address book updated.
Now you can update the user's personal address book information (Server, Mail File and Domain) automatically. Everytime a user opens a mail file, the script below executes and will only update the users personal address book information if all of the following conditions are met (in order):
1. The opened database is located on a server (not local)
2. Notes.ini file variable "$UpdateLocationDocument" does not exist or equals a value other than 0.
3. 30 days or more has lapsed since the last successful location document change
4. The opened database file name "mailxxx.nsf" matches the Mail File specified in the current user's Person Document in the address book.
Since Notes Administrators switch to users ID files from time to time, you do want their own location document to be modifed. To avoid this from happening, add the following line to your notes.ini file:
To force a user's location document to be updated next time they open their mail file, just delete both of these lines from the users notes.ini file:
Just Copy the script code below into each of the mail templates used in your system (like StdR46Mail
- mail46.ntf, etc) Database Script section, then wait for designer to run, or type "load design" at the servers console (not recommended to do this if people are accessing their mail files).
Each time a user opens their mail file, the following will be performed:
1. The Script will exit if the database is opened locally (not on server)
2. The Script checks the variable setting "$UpdateLocationDocument" in the notes.ini file.
The script will exit if this setting is 0 ie. $UpdateLocationDocument=0
This is so you can manually bypass this script via the notes.ini file (eg. for Notes Administrators)
3. The Script gets the variable setting "$DateLocationModified" in the notes.ini file.
This variable is a Date-Time setting, and will determine when script will process the function to update the personal address book.
4. The script gets current location document in the personal address book.
5. The script gets the users person document from the public address book.
6. The script exists if the mail file name in the users person document is different to the current database that was opened (where this script was executed from). So, if you have access to other mail files, the script will not update the location document with incorrect settings.
7. At this stage, the current user is the actual "owner" of the opened database, and the location document is then updated and saved. Information updated is MailFile, MailServer and Domain. You can optionally check or set other settings, such as "Mail File Location" (On Server), Internet browser and Proxy settings. You could also add a small script to ensure the "Calendar profile" document is always set to the correct user.
8. The notes.ini variable "$DateLocationModified" is then set to the current date time, so the script will not execute again until the number of days lapsed since the last modification.
If you need any scripts to do the above, drop me a line.
Any queries, contact me: firstname.lastname@example.org
Copy and paste the following code into the Database Script section of the mail templates:
########### CODE - DATABASE SCRIPT - POST OPEN EVENT (Declarations) Dim session As NotesSession Dim dbCurrent As NotesDatabase Dim sDateTime As String 'The script to update the location document will only run once every 30 days Const LapsedDaysForLocationUpdate = 30 Sub Postopen(Source As Notesuidatabase) Set session = New NotesSession Set dbCurrent = session.CurrentDatabase 'Only execute if the database is located on the server (not a local database) If Not dbCurrent.Server = "" Then 'Only update the users location document every 30 days If UpdateLocationDocument() Then 'Update the users location document Call UpdateUsersLocationDocument() End If End If End Sub Function UpdateLocationDocument() As Variant 'Last date the location document was modified Dim DateLocationModified As NotesDateTime 'Current Date Time now Dim DateTimeNow As NotesDateTime UpdateLocationDocument = False If (session.GetEnvironmentValue("UpdateLocationDocument",False)) = 0 Then Goto ExitUpdateLocationDoc 'Get the notes.ini file setting DateLocationModified Set DateLocationModified = New NotesDateTime(session.GetEnvironmentString("DateLocationModified",False)) 'Increase the number of days in the date with the minimum number of days we want to update the users location document Call DateLocationModified.AdjustDay(LapsedDaysForLocationUpdate) 'get the current date time now Set DateTimeNow = New NotesDateTime(Now) 'if the current date time has pasted the last time the location document was modified (plus 30 days) then 'set the return value to TRUE and store the current date time in a temporary variable (will be updated in the notes.ini later) If DateTimeNow.LSLocalTime > DateLocationModified.LSLocalTime Then UpdateLocationDocument = True Set DateTimeNow = New NotesDateTime(Now) sDateTime = DateTimeNow.LsLocalTime End If ExitUpdateLocationDoc: End Function Function UpdateUsersLocationDocument() Dim viewLocations As NotesView Dim viewPeople As NotesView Dim docLocation As NotesDocument Dim docPerson As NotesDocument Dim dbNAB As NotesDatabase Dim dbPAB As NotesDatabase Dim LocationDocument As String Dim nnUserName As NotesName Dim PersonalAddressBook As String Dim MailFile As String Dim MailFilePerson As String 'Get the personal address book from the notes.ini and remove any cascaded local address books PersonalAddressBook = Trim(session.GetEnvironmentString("Names",True)) If Instr(PersonalAddressBook, ",") > 0 Then PersonalAddressBook = Left$(PersonalAddressBook, Instr(PersonalAddressBook, ",") -1) Else If Instr(PersonalAddressBook, ";") > 0 Then PersonalAddressBook = Left$(PersonalAddressBook, Instr(PersonalAddressBook, ";") -1) End If End If 'Get the personal address book, exit if cannot be opened Set dbPAB = session.GetDatabase("", PersonalAddressBook) If dbPAB.IsOpen = False Then Goto FinishFunction 'Get the current location document in use, exit if any errors Set viewLocations = dbPAB.GetView("Locations") If viewLocations Is Nothing Then Goto FinishFunction LocationDocument = Trim(session.GetEnvironmentString("Location",True)) If LocationDocument = "" Then Goto FinishFunction LocationDocument = Left$(LocationDocument, Instr(LocationDocument, ",") -1) If LocationDocument = "" Then Goto FinishFunction Set docLocation = viewLocations.GetDocumentByKey(LocationDocument) If docLocation Is Nothing Then Goto FinishFunction 'Get the Public Address Book from the current server Set dbNAB = session.GetDatabase(dbCurrent.Server, "names.nsf") If dbNAB.IsOpen = False Then Goto FinishFunction 'Get the current users person document. Exit if user not in address book Set viewPeople = dbNAB.GetView("($VIMPeople)") Set nnUserName = New NotesName(session.UserName) Set docPerson = viewPeople.GetDocumentByKey(nnUserName.Abbreviated) If docPerson Is Nothing Then Goto FinishFunction 'Get the name of the mail file from the person document and current database MailFile = dbCurrent.FilePath MailFilePerson = docPerson.MailFile(0) If Lcase(Right$(MailFilePerson, 4)) <> ".nsf" Then MailFilePerson = MailFilePerson & ".nsf" End If 'Update the Location Document, if the mail file name in the address book matches the name of the current database If Lcase(MailFile) <> Lcase(MailFilePerson) Then Goto FinishFunction docLocation.MailFile = MailFile docLocation.MailServer = docPerson.MailServer(0) docLocation.Domain = docPerson.MailDomain(0) Call docLocation.Save(True, False) Call session.SetEnvironmentVar("DateLocationModified", sDateTime, False) FinishFunction: End Function