Return a list prompt containing all the agents in the current database.

This code is generic and can be modified to pull from other databases or execute the selected agent, etc... Used in a Button - AGENT LIST Selection from database
LotusScript


Sub Click(Source As Button)

	Dim workspace As New NotesUIWorkspace
	Dim session As New NotesSession
	Dim uidoc As notesuidocument 
	Set uidoc =workspace.currentdocument
	uidoc.EditMode = True
	Dim doc As NotesDocument
	Set doc = uidoc.document

	Dim targetdb As NotesDatabase
	Set targetdb = session.CurrentDatabase

	If Not targetdb.isopen Then
		Msgbox "The Target Database could not be opened." , 0 + 16
		Print "The Target Database could not be opened."
		Exit Sub
	End If

	Dim x As Integer
	Dim AgentArray() As String
	Redim AgentArray(x) As String

	Forall agent In targetdb.Agents
		If AgentArray(0) = "" Then
			AgentArray(x) = Ucase(agent.Name)
		Else
			x = x + 1
			Redim Preserve AgentArray(x) As String
			AgentArray(x) = Ucase(agent.Name)
		End If	
	End Forall

	Call SortArray(AgentArray)

	Dim agentNameIist
	agentNameIist = workspace.Prompt(PROMPT_OKCANCELLIST, "Choose Agent", "Please select the agent to process.", "" , AgentArray )

	Dim item As NotesItem
	Set item = doc.GetFirstItem( "target_agent" )

	If item Is Nothing Then
		doc.GSMUsersHost = agentNameIist 
	Else
		Call item.AppendToTextList(agentNameIist)	
	End If

	Call uidoc.Refresh

	Print "Agent Set"

End Sub


Sub SortArray(array)

	n = Ubound(Array) + 1

	For X = 1 To (n - 1) 'Perform the following loop for each value in the arrays
		J = X
		Do While J >= 1
			If Array(J) < Array(J - 1) Then ' Compares two values in the array
				ValueA = Array(J) ' Swap the values compared since the second is less than the first
				ValueB = Array(J - 1)
				Array(J) = ValueB
				Array(J - 1) = ValueA
				J = J - 1 ' Increment to the next two down in the array (descending to index 0 )
			Else
				Exit Do ' Index 0 reached, this batch has been sorted, goto next X index in the array and loop
			End If
		Loop
	Next
End Sub

Posted by fbrefere001 on Friday April 5, 2002