Sorting in LotusScript

In this (old) redbook, in Appendix B-4, you will find Lotus Script code for all the algorithms shown in the graph. I allwas use the QuickSort – think this works best in most situations.
Also check this Animated Sorting Algorithms site

Conclusion from the redbook:
Sorting can be a complex issue to decide. The amount of time taken to get

your data into arrays to allow you to use a sort routine may be longer than

the actual sorting. You then will need to get the sorted data out of those

arrays. You may be able to sort the data as you are preparing it or use the

resulting array as is.

There are many factors that influence the type of sort to use. Maybe creating

an extra view will solve all your problems.

In any case, you’ll need to think about your sorting needs. The examples

here use internal arrays of strings, so the problem is nicely encapsulated. For

these examples, the shell sort routine seems to be the easiest to code and

provides excellent performance.

If you are in a position to require a sophisticated sorting routine, spend some

time understanding these routines, and do some reading. The differences in

performance can be amazing!

Controlling the startup database in Lotus Notes

I have used three methods (at different customers):

  1. Setting the StartupDb parameter in notes.ini
  2. Creating a new frameset in bookmark.nsf – and launch this (from database launch properties on the bookmark.nsf)
  3. Creating a script that adds the database to the ‘Startup’ bookmark group (found in your bookmark bar, under ‘More Bookmarks’ )

1. Set a startup database in notes.ini
replicaId = Left( db.ReplicaID, 8 ) & “:” & Right( db.ReplicaID, 8 )
Call session.SetEnvironmentVar( “StartupDb”, replicaId, True )

Comments: will open the database in a secondary tab. Will have focus when launched

2. Create a new frameset in bookmark.ntf (note – make the changes in the template file)

  • Create a new frameset with one frame. Let the frame show a link – and include a notes url to the database/frameset you will open
  • Set the launch settings to open the new frameset (in the database properties box)
  • Copy the new bookmark.ntf to all clients

Comments: will be the first tab (instead of the workspace) and can’t be closed by the user

3. Place the bookmark in the Startup folder (under ‘more bookmarks’) using Lotus Script:

Comments: Opens a secondary tab, but will not have focus and will not load before user activates. You can launch several databases in this way. My personal favorite.

Function setStartup( intranetdb As NotesDatabase )
Dim session As New NotesSession

Dim bookmarkDb As NotesDatabase
Set bookmarkDb = session.GetDatabase( “”, “bookmark.nsf” )

Dim outline As NotesOutline
Dim entry As NotesOutlineEntry
Set outline = bookmarkDb.GetOutline( “UserBookmarkOrder” )

‘find the “Startup” folder
Set entry = outline.GetFirst
Do Until entry.Label = “Startup”
Set entry = outline.GetNext( entry )
If entry Is Nothing Then Print “Can’t find the entry – operation stopped” : Exit Function
Loop

‘Startup folder found. First, delete all bookmarks in thhis folder
Dim nextentry As NotesOutlineEntry
While entry.HasChildren
Set nextentry = outline.GetNext( entry )
Call outline.RemoveEntry( nextentry )
Wend

‘Next, create a new bookmark in the folder
Dim bookmark As NotesOutlineEntry
Set bookmark = outline.CreateEntry( intranetDb.Title, entry, True, True )
Call bookmark.SetNoteLink( intranetdb )
bookmark.ImagesText = “$Icon”

Call outline.Save()

Print intranetdb.Title & ” added to the startup folder”
End Function

Printing barcodes

Well, this can be done in several ways:

1. Printing to a ‘barcode’ printer (with a builtin barcode font).
Have been using a Citizen CLP-621 printer. The print job is just a text file, created with Lotus Script. Text file contains all the control codes for the printer, e.g. page width, borders, font size etc. The manual were quite good – with lots of details and examples.
Only one problem – how to copy/spool the print file to the printer? Found a small freeware spooler program -> http://www.lerup.com/printfile/ When started and configured, it can copy all files from a folder to any printer
It works perfectly 🙂

2. Install your own barcode font and print using word or Lotus Notes
Found the fonts on http://www.idautomation.com. They have all fonts, with documentation and Lotus Script code to generate the barcode string (convert a number to a barcode string with checksums). Just make sure to select the right font. Some fonts doesn’t support charecters and some doesn’t support special charecters – and do check that your scanners support the selected font.
When you have the font, it is simple to create a print form in Notes. Did try to use Microsoft word – but some barcodes had special chars that was destoyed by Word, and didn’t work…

My Favorites database properties

  • Don’t maintain unread marks: This can ruin performance – unread marks should only be used if really needed
  • Don’t use the “Don’t support specialized responses hierachy” – If you do, you can read responses from Lotus Script (doc.responses.count is always zero)
  • Use LZ1 compression: Yep – this makes sense. Less storage and less traffic
  • Allow more fields in database. Can’t find any drawbacks from this – and sometimes it is needed -> so, it’s an ‘always on’ for me
  • Allow soft deletions: Users loves this. Just remember to set the expire time high (336 for 2 weeks or more)
  • I also limit the $UpdatedBy and $Revisions fields – no need to track everything

    More info here

@ExpandNameList

Nice (but undocumented) function to expand a group:

@ExpandNameList( server:file; groupname )

Has been there since release 5, but it still works.

Updated 09.11.2011

Notice: @ExpandNameList will only work on Mail groups – ‘Access Control List only’ groups are not included (will return an empty array).

Sample script to resolve a list with mixed groups and functions:

%REM
Find all members in a group or list of groups and persons
Will also work when running on a local replica (but requires server access)
%ENDREM
Function getMembers( GroupOrNameList As Variant ) As Variant 

        Dim members As Variant 

        'find a server (use the homeserver if script is running on a local database)
        Dim server As Variant
        server = Evaluate(|@if( @subset( @dbname;1 ) = ""; @LocationGetInfo([HomeServer]); @subset( @dbname;1 ))|) 

        If Isarray( GroupOrNameList ) Then
                Forall member In GroupOrNameList
                        If Isempty( members ) Then
                                members = getMembers( member )
                        Else
                                members = Arrayappend( members, getMembers( member ))
                        End If
                End Forall
        Else
                members = Evaluate(|@ExpandNameList( "| & server( 0 ) & |":"names.nsf"; "| & GroupOrNameList & |" )|)
        End If 

                'fix problem with persons with an forward address on the person document
        Dim i As Integer
        Dim v As Variant
        For i=0 To Ubound(members)
                If lcase( Left(members(i), 3))<>"cn=" Then
                        v = Evaluate(|@NameLookup( [NoUpdate] ; "|+members(i)+|"; "fullname")|) 

                        if v( 0 ) = "" then
                                v = Evaluate(|@NameLookup( [NoUpdate] ; "|+strleftback( members(i), "@" )+|"; "fullname")|)
                        end if 

                        If Not Isempty(v) Then
                                members(i)=v(0)
                        End If
                End If
        Next 

                'remove duplets
        members = Arrayunique( members,5 ) 

                'return
        getMembers = members
End Function

Links

Undocumented – but needed…

Found these hidden features in Lotus Notes:

1: Set coll = db.CreateDocumentCollection
//no more set coll = db.GetProfileDocCollection( don’t find me rubbish )

2: NotesView.GetColumnValues (@DbColumn in LS)
//no more evaluate( @dbcolumn( …. ) )

Just a shame they didn’t find there way into the help file……

More info here -> http://www.lotus911.com/nathan/escape.nsf/D6Plinks/NTFN-7GTSH4