Lotusscript to delete private views on database queryclose()

I’ve been working on a helpdesk app which contains a private on first use view. The idea is to let users see only tickets they’ve created. As you would expect, it’s very buggy. From looking at forum posts, I picked up that it’s usually a good idea to remove the user’s private view on database close, so I went to the database script and inserted the following code into the queryclose() event:

Sub Queryclose(Source As Notesuidatabase, Continue As Variant)

Dim session As New NotesSession

Dim view As NotesView

Dim nam As NotesName

Set nam = session.CreateName(session.UserName)

Set view = source.database.GetView( “My_Tickets” )

If Not view Is Nothing Then

If view.isPrivate Then

If view.Readers(0) = nam.Canonical Then

view.remove

End If

End If

End If

End Sub

When I implemented this script, all heck broke loose. I got red screens of death. My own private view got deleted and would not recreate. When I tried to manually remove my own private view, it told me it had already been deleted, but continued to appear in the views. Most importantly, when switching between locations to test as different users, the view was not changing accordingly. So what’s wrong with my code? Do I need to scrap this feature all together? I hope 7 does a better job with private on first use views . . .

Thanks.

Subject: Lotusscript to delete private views on database queryclose()

If you are not using @Username in any of the columns of that view, then get rid of the “Shared Private on First use” view. Delete it and recreate the same as a “Shared View”.

Categorize the first column by its Author.

Create a form

Embed this view in that form

In the embedded view event of the form “Show single Category”, write @Name([CN]; @UserName) or just @Username as per your design which should match the value in the first categorized column of that view.

If you are displaying this view after a click on a link in navigator, change the formula in link so that it composes the form (with the embedded view). Create a computed for display SaveOptions text field and put the value as “0”, to restrict the save on it.

Subject: RE: Lotusscript to delete private views on database queryclose()

Thanks for the quick response. That will definately work as a backup plan if I can’t get that private on first use view to work properly.

Subject: RE: Lotusscript to delete private views on database queryclose()

Then you need to try this way. There are some issues if you use getView method for a “private view”. Loop thru all views, get private view and then remove it.

Forall x In db.Views

    If x.IsPrivate Then

        readers = x.Readers			

        If Isarray(readers) Then

             If Ubound(readers) < 1 Then

                 If readers(Lbound(readers)) = sess.Username Then   'private view on server

					          x.Remove

     End If

  End If

         End If

    End If

End Forall

Subject: I decided to take your suggestion about the embedded view . . .

It worked much better than I expected. I’ve decided to stick with that instead of dealing with Private views. Thanks for the suggestion.