How to update Lotus Notes documents after an employee last-name change


Sometimes when a Lotus Notes user gets married or divorced, her last name changes. When this happens, she receives a new Lotus Notes ID file with her new last name. Unfortunately, she may no longer have proper access to Lotus Notes documents because the documents still contain her old last name. This LotusScript utility solves that problem. It updates all documents in the Lotus Notes database with the employee's new last name.

 Sub Initialize
Dim s As NotesSession, 
dc As NotesDocumentCollection, 
doc As NotesDocument
Dim sOldName As String, 
sNewName As String, bSave As Boolean

sNewName = "Elin Woods"
sOldName = "Elin Nordegren"

Set s = New NotesSession
Set dc = s.CurrentDatabase.AllDocuments 
  'check every document in the database
Set doc = dc.GetFirstDocument 
While Not doc Is Nothing
bSave = False
Forall  niItem In doc.Items
'Do not change special $ fields
'Only change AUTHORS, NAMES, 
If Left(niItem.Name,1) <> "$" 
And (niItem.Type = AUTHORS Or niItem.Type = 
NAMES  Or niItem.Type = READERS _
Or niItem.Type = TEXT Or niItem.Type = 
USERDATA Or niItem.Type = USERID) Then
If Instr (niItem.Text , sOldName) > 0 
Then  'Change the name only if it exists 
anywhere in the field
Call doc.ReplaceItemValue(niItem.Name, 
ReplaceText(niItem.Values, sNewName, sOldName))
bSave = True
End If
End If
End Forall
If bSave = True Then Call doc.Save(True, False)  
'only save if changed
Set doc = dc.GetNextDocument(doc)
End Sub

Function ReplaceText(ValueList As Variant, 
sNewText As String, sOldText As String)  As Variant
Dim tmpValueList As Variant, sLeft As String, 
sRight As String

Redim tmpValueList(Ubound(ValueList))  
'create temp array of values
For i = 0 To Ubound(ValueList) 'check each value in array
If Instr (ValueList(i), sOldText) > 0 
Then 'does the old text value exist in this item?
sLeft = Left(ValueList(i), 
Instr (ValueList(i), sOldText) - 1)  'left of old text
sRight = Right(ValueList(i), 
Len(ValueList(i)) - Instr (ValueList(i), 
sOldText) - Len(sOldText) + 1) 'right of old text
tmpValueList(i) = sLeft & sNewText 
& sRight  'replace old text with new text
tmpValueList(i) = ValueList(i)
End If
ReplaceText = tmpValueList

End Function


When you do the rename in the Admin client with the help of AdminP, the process will do this job for you. In the tip, the author renamed the person in all Reader and Author fields. The only thing you have to do is check in the ACL whether this option is set or not.
—Axel M.


I would rather have the Lotus Notes database Advanced ACL setting for the administration server apply one of the actions to either modify all Readers and Authors fields or modify all Names fields that the administration server should process. Having this set and using the standard Administration Process (AdminP) will achieve the same result without any programming. As developers, we never know when a name will change, so using AdminP and the correct ACL setting is the best way to go.
—John T.

Do you have comments on this tip? Let us know.

Related information from SearchDomino.com:

  • FAQ: LotusScript advice
  • Learning Guide: LotusScript
  • Expert Advice: Name change and user didn't receive email to accept it
  • Reference Center: LotusScript tips and resources

    This tip was submitted to the SearchDomino.com tip library by member Scott Huyser. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

    This was first published in February 2007

  • There are Comments. Add yours.

    TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

    REGISTER or login:

    Forgot Password?
    By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
    Sort by: OldestNewest

    Forgot Password?

    No problem! Submit your e-mail address below. We'll send you an email containing your password.

    Your password has been sent to:

    Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.