Find and delete local contacts in names.nsf

We recently changed domino domains, but as many users saved addresses in the local names.nsf they now fail to deliver.

It's obviously time consuming to clear everyone's address book and not all users are willing to do it.

I was hoping someone has some code I could send in a button to everyone via email which would do the following

Find & Delete all entries in names.nsf which contain @domain1 name or @domain2, etc..
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve KnightIT ConsultancyCommented:
Do you want to remove the entries altogether, or just remove the email address, or change Name@domain1 to Name@NewDomain?  

Only reason is whether the user stores any other information in their PAB entries people?

There are a couple of other scripts in my scripts archive at but not one specifically to do this.

Let me know whether they are to be deleted or amended and can knock something up.  Are there two domains, and are we talking domino domains or also smtp addresses.

Also do you want "recent contacts" cleared altogether or stripped of these people too?

UnifraxAuthor Commented:
Yeh delete the entries all together.
Contact details should be available from the server address book even if they have them.

There are multiple domino domains (about 6 in total).

Recent contacts should be completely cleared too.


Steve KnightIT ConsultancyCommented:
Give this a try... it displays the entries it would delete in the status bar at the bottom of the screen, click on it to show previous entries.  It prompts you yes/no at the moment for whether to delete or not.

I assumed would just be able to find entries in the MailDomain field but have seen ones that contain full name of first lastname@DOMAIN in the fullname and nothing in MailDomain so at the moment it looks in the Fullname fields for @domainname and in the MaiLDomain field for domainname.  As it stands it can search for 6 different domains to remove, just change the DIM CheckNames entry and contents of that array to do a different number.

Each document to delete is added to a document collection then deleted at the end only if you say "yes".

Not the neatest or best way of doing it but works for me.  Give it a try first to check ok then remove the REM before the actual delete line at the end of the main code section.


Dim CheckNames (5) As string

Function CheckDomain(check_doc As NotesDocument) As Boolean
	Dim MailDomain As String
	Dim n As Integer
	MailDomain = check_doc.Getitemvalue("MailDomain")(0)
	If MailDomain="" Then
		For n= 0 To UBound(CheckNames)
			If InStr(1,MailDomain,CheckNames(n)) Then 
				Print check_doc.FullName(0)  &" has domain as " & MailDomain
			End If
	End If
End Function

Function CheckName(check_doc As NotesDocument) As Boolean
	Dim FullName As String
	Dim n As integer
	FullName = Join(check_doc.Getitemvalue("FullName"),",")
	For n= 0 To UBound(CheckNames)
		If InStr(1,FullName,"@" & CheckNames(n)) Then 
			Print FullName
		End if
End Function

[u]and the main code for Click / Initialize etc.[/u]

Dim db As New NotesDatabase ("","names.nsf")

	Dim session As New NotesSession
	Dim ws As New NotesUIWorkspace

	Dim viewusers As NotesView
	Dim viewrecent As NotesView
	Dim doc As NotesDocument
	Dim dc_delete As NotesDocumentCollection
	Dim count As Integer, countchanged As Integer, countrecent As integer
	Dim ans As integer
	Set viewusers=db.getview("($People)")
	Set viewrecent=db.getview("(RecentContacts)")
	REM Get empty document collection
	'Set dc_delete =viewusers.getalldocumentsbykey("*GetEmptyDocollection*")
	REM Remove all entries from Recent Contacts
	Set dc_delete = db.Search({SELECT @UpperCase($AutoCreatedList)  = "DIP"}, Nothing, 0)
	Set doc=viewusers.getfirstdocument
	If doc Is Nothing And countrecent=0 Then
		MsgBox "There were no people documents found"
		Exit Sub
	End if
		If CheckName(doc) Or CheckDomain(doc) Then
			Call dc_delete.adddocument(doc)
		End if
		Set doc=viewusers.getnextdocument(doc)
	Loop Until doc Is nothing
	ans=MsgBox ("Processed " & count & " people from your address book." & Chr(13) _
	   & "Need to remove " & countchanged & " people plus " & countrecent & " recent contacts" & Chr(13)& Chr(13) _
	   &  "Please confirm delete.",3+32,"DELETE ENTRIES?")
	If Ans=6 Then
		REM Call dc_delete.Removeall(false)
		MsgBox "Documents deleted"
		MsgBox "No changes made"
	End if

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
UnifraxAuthor Commented:
Perfect! Thanks Steve, this worked great!
Steve KnightIT ConsultancyCommented:
No problem, glad it helped.... have added it to my scripts lists now too.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.