<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Domino &#8211; Tjitjing Blog</title>
	<atom:link href="http://localhost/index.php/tag/domino/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.tjitjing.com/</link>
	<description>This is my blog on technology related stuff and on occation other things too...</description>
	<lastBuildDate>Tue, 30 May 2006 21:28:00 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.16</generator>
	<item>
		<title>How to sort a NotesDocumentCollection in Lotusscript</title>
		<link>https://blog.tjitjing.com/index.php/2006/05/how-to-sort-notesdocumentcollection-in.html</link>
					<comments>https://blog.tjitjing.com/index.php/2006/05/how-to-sort-notesdocumentcollection-in.html#comments</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Tue, 30 May 2006 21:28:00 +0000</pubDate>
				<category><![CDATA[Lotus Notes]]></category>
		<category><![CDATA[Lotusscript]]></category>
		<category><![CDATA[Domino]]></category>
		<category><![CDATA[IBM Lotus]]></category>
		<guid isPermaLink="false">http://blog.tjitjing.com/index.php/2006/05/how-to-sort-a-notesdocumentcollection-in-lotusscript.html</guid>

					<description><![CDATA[This Lotusscript function sorts a document collection on one or multiple fields. I have previously used several other algorithms that use a view to sort the collection, these however have the drawback that they become very inefficient (i.e. slow) as the number of documents in the view used for sorting grows. The solution presented below&#8230; <a class="more-link" href="https://blog.tjitjing.com/index.php/2006/05/how-to-sort-notesdocumentcollection-in.html">Continue reading <span class="screen-reader-text">How to sort a NotesDocumentCollection in Lotusscript</span></a>]]></description>
										<content:encoded><![CDATA[<p><strong>This Lotusscript function sorts a document collection on one or multiple fields.</strong></p>
<p><strong><br />
</strong><strong>I have previously used several other algorithms that use a view to sort the collection, these however have the drawback that they become very inefficient (i.e. slow) as the number of documents in the view used for sorting grows. The solution presented below does not have this problem. </strong></p>
<p>It has been developed and tested in Lotus Notes 6.5.3 but should work in all ND6 (release 6) and possibly earlier Lotus Notes releases too (if you test this successfully or unsuccessfully write a comment to this post and everyone will know).</p>
<p>Example of use:</p>
<p><code>Dim fieldnames(0 To 2) As String<br />
fieldnames(0) = "SKU"<br />
fieldnames(1) = "OrderDate"<br />
fieldnames(2) = "Client"<br />
Set collection = SortCollection (collection, fieldnames) </code></p>
<p>Function to sort DocumentCollection:</p>
<p><code>Function SortCollection(coll As NotesDocumentCollection, fieldnames() As String) As NotesDocumentCollection</code></p>
<p><code>' ------------------------------------------------<br />
' --- You may use and/or change this code freely<br />
' --- provided you keep this message<br />
' ---<br />
' --- Description:<br />
' --- Sorts and returns a NotesDocumentCollection<br />
' --- Fieldnames parameter is an array of strings<br />
' --- with the field names to be sorted on<br />
' ---<br />
' --- By Max Flodén 2005 - http://www.tjitjing.com/<br />
' ------------------------------------------------</p>
<p>Dim session As New NotesSession<br />
Dim db As NotesDatabase<br />
Dim collSorted As NotesDocumentCollection<br />
Dim doc As NotesDocument<br />
Dim i As Integer, n As Integer<br />
Dim arrFieldValueLength() As Long<br />
Dim arrSort, strSort As String<br />
Dim viewname As String, fakesearchstring As String</p>
<p>viewname = "$All" 'This could be any existing view in database with first column sorted<br />
fakesearchstring = "zzzzzzz" 'This search string must NOT match anything in view<br />
Set db = session.CurrentDatabase</p>
<p>' ---<br />
' --- 1) Build array to be sorted<br />
' ---</p>
<p>'Fill array with fieldvalues and docid and get max field length<br />
Redim arrSort(0 To coll.Count -1, 0 To Ubound(fieldnames) + 1)<br />
Redim arrFieldValueLength(0 To Ubound(fieldnames) + 1)<br />
For i = 0 To coll.Count - 1<br />
Set doc = coll.GetNthDocument(i + 1)<br />
For n = 0 To Ubound(fieldnames) + 1</p>
<p>If n = Ubound(fieldnames) + 1 Then<br />
arrSort(i,n) = doc.UniversalID<br />
arrFieldValueLength(n) = 32<br />
Else<br />
arrSort(i,n) = "" &amp; doc.GetItemValue(fieldnames(n))(0)<br />
' Check length of field value<br />
If Len(arrSort(i,n)) &gt; arrFieldValueLength(n) Then<br />
arrFieldValueLength(n) = Len(arrSort(i,n))<br />
End If<br />
End If</p>
<p>Next n<br />
Next i</p>
<p>'Merge fields into list that can be used for sorting using @Sort function<br />
For i = 0 To coll.Count - 1<br />
If Not strSort = "" Then strSort = strSort &amp; ":"<br />
strSort = strSort &amp; """"<br />
For n = Lbound(fieldnames) To Ubound(fieldnames) + 1<br />
strSort = strSort &amp; Left(arrSort(i,n) &amp; Space(arrFieldValueLength(n)), arrFieldValueLength(n))<br />
Next n<br />
strSort = strSort &amp; """"<br />
Next i</p>
<p>' ---<br />
' --- 2) Sort array<br />
' ---<br />
arrSort = Evaluate("@Sort(" &amp; strSort &amp; ")")</p>
<p>' ---<br />
' --- 3) Use sorted array to sort collection<br />
' ---<br />
Set collSorted = coll.Parent.GetView(viewname).GetAllDocumentsByKey(fakesearchstring)</p>
<p>For i = 0 To Ubound(arrSort)<br />
Set doc = db.GetDocumentByUNID(Right(arrSort(i), 32))<br />
Call collSorted.AddDocument(doc)<br />
Next i</p>
<p>' ---<br />
' --- 4) Return collection<br />
' ---<br />
Set SortCollection = collSorted</p>
<p></code><code>End Function<br />
</code></p>
<p><em>(This article is previously published and has been moved to this blog)</em><br />
<em></em><br />
<em>[Update: Instead of using Evaluate and @Sort in section 2 in the code you can of course use any of your favourite sort routines. Or search the Net for one, there are many out there.]</em></p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.tjitjing.com/index.php/2006/05/how-to-sort-notesdocumentcollection-in.html/feed</wfw:commentRss>
			<slash:comments>18</slash:comments>
		
		
			</item>
	</channel>
</rss>
