Home > Domino Tips > Administrator > Address Book > Script To Sort Groups In R4
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ADDRESS BOOK

Script To Sort Groups In R4


Bob Pratico
11.17.1999
Rating: --- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


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

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Address Book
Formula language button manages Deny Access list searches
Find a Lotus Notes user within NAB Deny Access groups
Synchronize LinkedIn contacts with Lotus Notes Domino
How to correct Lotus Notes public key mismatches in four easy steps
Creating a Lotus Notes Personal Address Book replica
Admin user unable to create NAB
@Transform formula for use in R6
Change NAB while maintaining integrity of documents
NAB: A key piece of the Domino administration puzzle
Build an extended directory catalog

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts