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..
UnifraxAsked:
Who is Participating?
 
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.

Steve

[u](Declarations)[/u]
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
		CheckDomain=False
	Else
		For n= 0 To UBound(CheckNames)
			If InStr(1,MailDomain,CheckNames(n)) Then 
				CheckDomain=True
				Print check_doc.FullName(0)  &" has domain as " & MailDomain
			End If
		Next
	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 
			CheckName=True
			Print FullName
		End if
	Next
	
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
	
	CheckNames(0)="Domain1"
	CheckNames(1)="Domain2"
	CheckNames(2)="Domain3"
	CheckNames(3)="Domain4"
	CheckNames(4)="Domain5"
	CheckNames(5)="Domain6"
	
	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)
	countrecent=dc_delete.count
				
	Set doc=viewusers.getfirstdocument
	
	If doc Is Nothing And countrecent=0 Then
		MsgBox "There were no people documents found"
		Exit Sub
	End if
	
	count=0
	countchanged=0
	Do   
		count=count+1
		If CheckName(doc) Or CheckDomain(doc) Then
			Call dc_delete.adddocument(doc)
			countchanged=countchanged+1
		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"
	Else
		MsgBox "No changes made"
	End if

Open in new window


Steve
0
 
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 http://scripts.dragon-it.co.uk/ 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?

Steve
0
 
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.

Thanks!!

Jack
0
 
UnifraxAuthor Commented:
Perfect! Thanks Steve, this worked great!
0
 
Steve KnightIT ConsultancyCommented:
No problem, glad it helped.... have added it to my scripts lists now too.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.