Manage Learn to apply best practices and optimize your operations.

Script To Sort Groups In R4

While R5 has a built-in action to alphabetically sort groups in the Address
Book, R4.x has no feature. This script sorts a group alphabetically (by first
name) using an indexed shellsort.

Sub Initialize
Dim session As New NotesSession
Dim dc As NotesDocumentCollection
Dim db As NotesDatabase
Dim PersonDoc As NotesDocument
Dim GroupView As NotesView
Dim GroupDoc As NotesDocument
Dim MemberItem As NotesItem

REM Get current session info
Set db = session.CurrentDatabase
Set dc = db.UnprocessedDocuments

REM Setup Logging
Dim AgentLog As NotesLog
Set AgentLog = New NotesLog ("Group Log" )
Call AgentLog.OpenAgentLog

REM Loop through selected groups
REM Loop through all the documents in the database
For doc% = 1 To dc.Count
Set GroupDoc = dc.GetNthDocument(doc%)

REM Groups only
If (GroupDoc.Type(0) = "Group") Then

Set MemberItem = GroupDoc.GetFirstItem("Members")

REM Print name
AgentLog.LogAction("Sorting group: " & GroupDoc.ListName(0))
Print "Sorting group: " & GroupDoc.ListName(0)

REM Indexed Shellsort
REM Determine the array size
ArraySize% = 0
Forall items In GroupDoc.Members
ArraySize% = ArraySize% + 1
End Forall

REM Initialize Index array
Redim IndexArray% (ArraySize%)
For x% = 0 To ArraySize%
IndexArray%(x%) = x%
Next
AgentLog.LogAction("Number of Members: " & ArraySize%)

REM Find starting point
Dim h As Integer
For h% = 1 To ArraySize% / 9
h% = h% * 3
Next

REM Walk back 40, 13, 4, 1 ...
Dim Name1 As NotesName
Dim Name2 As NotesName
While h% > 0
For i% = h% To ArraySize% - 1
v% = IndexArray%(i%)
j% =
i%
Set Name1 = New NotesName
(GroupDoc.Members(IndexArray%(j%-h%)))
Set Name2 = New NotesName (GroupDoc.Members(v%))

REM Might choose to sort by something besides first name
While ((j% >= h%) And (Name1.Common > Name2.Common))
IndexArray%(j%) = IndexArray%(j%-h%)
j% = j% - h%
If (j% > h%) Then
Set Name1 = New NotesName
(GroupDoc.Members(IndexArray%(j%-h%)))
Set Name2 = New NotesName
(GroupDoc.Members(v%))
End If
Wend
IndexArray%(j%) = v%
Next
h% = h% / 3
Wend

REM Move results to a string array
Redim StringArray (0 To ArraySize%-1)
For x% = 0 To ArraySize%-1
AgentLog.LogAction(x% & " = " &
GroupDoc.Members(IndexArray%(x%)))
StringArray(x%) = GroupDoc.Members(IndexArray%(x%))
Next

REM Replace original data
GroupDoc.Members = StringArray

REM Save results
Call GroupDoc.Save(False,False)
End If
Next
AgentLog.Close
End Sub
This was last published in November 2000

Dig Deeper on Domino Resources - Part 5

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close