Remove user from field?

HiWhen a open my db it’s start a agent in postopen.

I run this code:

========

Sub Initialize

Dim wks As New NotesUiWorkspace

Dim session As New NotesSession

Dim db As NotesDatabase

Dim SearchView As NotesView

Dim activeDoc As NotesDocument

Dim docColl As NotesDocumentCollection

Dim item As notesitem



Set db = session.CurrentDatabase

Set SearchView = db.GetView( "(CheckActiveUser)" )

Set docColl = searchview.GetAllDocumentsByKey("Active")



If docColl.Count >0 Then

	Set activeDoc = docColl.GetFirstDocument

	While Not activeDoc Is Nothing

		Set item = activeDoc.GetFirstItem("ActiveInThisDB")

		If Not item.Contains(session.UserName) Then

			' Mark docoment as read.

			Call item.AppendToTextList(session.UserName)

			Call activeDoc.Save(True,False)

		End If

		

		Set activeDoc = docColl.GetNextDocument(activeDoc)			

	Wend

	

End If

End Sub

========

It’s set username for the person who open the db in a form with a field. I could be up to 25 users in the same time.

It’s work fine but now will a try to remove the user when they leave the db, how will a do that the easy way.

Subject: Remove user from field?

Hi,

An idea :

In DB QueryClose event use an LS agent with Evaluate and @Trim(@Replace(…)) to remove the name of user name from field, something like this :

Dim wks As New NotesUiWorkspace

Dim session As New NotesSession

Dim db As NotesDatabase

Dim SearchView As NotesView

Dim activeDoc As NotesDocument

Dim docColl As NotesDocumentCollection

Dim item As notesitem

Dim result As Variant

Set db = session.CurrentDatabase

Set SearchView = db.GetView( “(CheckActiveUser)” )

Call SearchView.Refresh

Set docColl = searchview.GetAllDocumentsByKey(“Active”)

If docColl.Count > 0 Then

Set activeDoc = docColl.GetFirstDocument

While Not activeDoc Is Nothing

userNAme = session.UserName

result = Evaluate(|@Trim(@Replace(|+userName+|;|+activeDoc.ActiveInThisDB+|)))

activeDoc.ActiveInThisDB = result

Call activeDoc.Save(True,False)

Set activeDoc = docColl.GetNextDocument(activeDoc)

Wend

End If

End Sub

Sorry, if there are syntax errors , but the idea is there…)

HTH

Thierry

Subject: RE: Remove user from field?

I get an error on Evulate, did i miss something there?

========

Sub Queryclose(Source As Notesuidatabase, Continue As Variant)

Dim wks As New NotesUiWorkspace

Dim session As New NotesSession

Dim db As NotesDatabase

Dim SearchView As NotesView

Dim activeDoc As NotesDocument

Dim docColl As NotesDocumentCollection

Dim item As notesitem

Dim result As Variant



Set db = session.CurrentDatabase

Set SearchView = db.GetView( "(CheckActiveUser)" )

Call SearchView.Refresh

Set docColl = searchview.GetAllDocumentsByKey("Active")

If docColl.Count > 0 Then

	Set activeDoc = docColl.GetFirstDocument

	While Not activeDoc Is Nothing

		userName = session.UserName

		

		result = Evaluate(|@Trim(@Replace(| & activeDoc.ActiveInThisDB & |;| & userName & |;|  & "" & |))|)

					

		activeDoc.ActiveInThisDB = result

		Call activeDoc.Save(True,False)

		Set activeDoc = docColl.GetNextDocument(activeDoc)

	Wend

End If

End Sub

========

Kind regards

Fredrik