Lotus Script Help ---> Resource Database

I noticed in my log file I had the follow message “Can’t find $BusyName field on profile” and “Invalid or nonexistent document” in my Resource Database. I found some code on this forum that looks like it will work to resolve my problem but I can’t seem to get it to work.

When I run the code it give me the following error - “Document Already exists in this collection”. Can someone help me with this code?

Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim docDelete As NotesDocument

Dim Profile_Collection As NotesDocumentCollection

Dim x As Integer

Dim xDelete As Integer

Dim unidJB As String

Set db = session.CurrentDatabase

If db.CurrentAccessLevel <> Acllevel_manager Then

Messagebox “You must have manager access to use this program”,16,“Access Error”

Exit Sub

End If

Set Profile_Collection = db.GetProfileDocCollection(“calendarprofile”)

If Profile_Collection.Count = 0 Then

Messagebox “Unable to Find any CalendarProfile Documents in the Database.”,64,“Found Nothing”

Exit Sub

End If

Set doc = Profile_Collection.GetFirstDocument

xDelete = 0

x = Profile_Collection.count

Do While Not (doc Is Nothing)

If Not doc.HasItem(“$BusyName”) Then

xDelete = xDelete + 1

unidJB = doc.Universalid

Set doc = Nothing

Set docDelete = db.GetDocumentByUNID(unidJB)

Call docDelete.Remove(True)

Set Profile_Collection = db.GetProfileDocCollection(“calendarprofile”)

Set doc = Profile_Collection.GetFirstDocument

Else

Set doc = Profile_Collection.GetNextDocument(doc)

End If

Loop

Messagebox “Found " & Cstr(x) & " CalendarProfile Documents in the Database.” & Chr(13) & Chr(10) &_

“Deleted " & Cstr(xDelete) & " of them that did not have the $BusyName field.”,64,“Done”

Subject: Why are you re-getting your collection?

I would suggest:

Set doc = Profile_Collection.GetFirstDocument

xDelete = 0

x = Profile_Collection.count

Do While Not (doc Is Nothing)

Set docDelete = doc

Set doc = Profile_Collection.GetNextDocument(doc)

If Not docDelete.HasItem("$BusyName") Then

   xDelete = xDelete + 1

  Call docDelete.Remove(True)

End If

Loop

Subject: RE: Why are you re-getting your collection?

I agree and thank you for your response.

Before I set the doc=Profile_Collection.GetFirstDocument wouldn’t I have to define my collection right? such as 'Set Profile_Collection = db.GetProfileDocCollection(“calendarprofile”)

Here is what I have with your updates:

Set Profile_Collection = db.GetProfileDocCollection(“calendarprofile”)

If Profile_Collection.Count = 0 Then

	Messagebox "Unable to Find any CalendarProfile Documents in the Database.",64,"Found Nothing"

	Exit Sub

End If



Set doc = Profile_Collection.GetFirstDocument

xDelete = 0

x = Profile_Collection.count



Do While Not (doc Is Nothing)		

	Set docDelete = doc

	Set doc = Profile_Collection.GetNextDocument(doc)

	If Not doc.HasItem("$BusyName") Then

		xDelete = xDelete + 1

		'Call docDelete.Remove(True)

	End If

Loop

And I still receive the error “Document Already in this collection” on line → Set Profile_Collection = db.GetProfileDocCollection(“calendarprofile”)

Any suggestions on the setting the initial Profile_Collection to get all the calendar profile documents?

Subject: I put the following code in a button in a memo in my mail database and it worked properly.

Also you have 1 error in your code , it should be: If Not docDelete.HasItem(“$BusyName”) Then

My code that worked:

Sub Click(Source As Button)

Dim s As New NotesSession

Dim db As NotesDatabase

Set db = s.CurrentDatabase

Dim doc As NotesDocument

Dim deldoc As NotesDocument

Dim pcol As NotesDocumentCollection



Set pcol = db.GetProfileDocCollection("calendarprofile")

If pcol.Count = 0 Then

	Messagebox "No CalendarProfile Documents in the Database.",64,"Found Nothing"

	Exit Sub

End If



Set doc = pcol.GetFirstDocument

xDelete = 0

x = pcol.count



Do While Not (doc Is Nothing)		

	Set deldoc = doc

	Set doc = pcol.GetNextDocument(doc)

	If Not deldoc.HasItem("$BusyName") Then

		xDelete = xDelete + 1

		Call deldoc.Remove(True)

	End If

Loop

Msgbox "Deleted: " + Cstr(xDelete)

End Sub

Subject: RE: I put the following code in a button in a memo in my mail database and it worked properly.

The big question is does your code work from a view in a room reservation database?

Subject: Yes it does in my RR db.