Manage Learn to apply best practices and optimize your operations.

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

After a last-name change, a Lotus Notes user may no longer have proper access to Lotus Notes documents, because they still contain her old last name. This LotusScript utility from member Scott Huyser solves that problem. It updates all documents in the Lotus Notes database with the employee's new last name.


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

  • 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 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.

  • Dig Deeper on LotusScript

    • Favorite iSeries cheat sheets

      Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ community. These cheat ...

    • HTML cheat sheet

      This is a really cool cheat sheet if you're looking to learn more about HTML. You'll find just about everything you every wanted ...

    • Carol Woodbury: Security

      Carol Woodbury