1
votes

I am attempting to populate the choices on a Notes Form Listbox using Lotusscript. My theory being. In the doc Onload event I retreive my data from a View adding it to a hidden field. I then use that field as the choices selection formula for the Listbox.

My thinking seems correct as if I use @FontList in the hidden field then all the fonts are available in the Listbox, but using the script below the Listbox options are blank despite both methods producing a field with Data Type: Text List

Maybe I can't populate the choices using Onload in this way so, any suggestions on how to dynamically populate the choices of a Listbox using Lotusscript would be appreciated.

Many thanks

Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim col As NotesViewEntryCollection
Dim entry As NotesViewEntry
Dim item As NotesItem
Dim doc As NotesDocument
Dim coName As String

Set db = session.CurrentDatabase
Set view = db.GetView("All Customers")
Set col = view.AllEntries 'This will be subset if I can get it working 
Set entry = col.GetFirstEntry

Set doc = Source.Document
Set item = doc.GetFirstitem( "FieldToStoreChoices" )


While Not (entry Is Nothing)
    coName = entry.ColumnValues(0)
    Call item.AppendToTextList( coName & ";")
    Set entry = col.GetNextEntry(entry)
Wend
1
Put this in the PostOpen method for the form. Use item to populate a Choices field, then use the Choices field as the formula for the list field choices. - teleman

1 Answers

1
votes

There is one (little) error in your code but that will only result in slightly wrong values before the first Form refresh and is not the cause that your approach does not work:

AppendToTextList already creates a multivalue item. Appending the semicolon is not necessary in this line:

Call item.AppendToTextList( coName & ";")

This is sufficient:

Call item.AppendToTextList( coName )

The problem is: by default a listbox „calculcates“ its choices on open and does NOT change after that.

You need to set the option „Refresh choice on document refresh“ on the same tab where you enter the fieldname for the choices.

And then you might have to add a

Call Source.Refresh

After your code to make the changes visible.

One more comment to Duston‘s answer: In Version 6 IBM tried to „unify“ events between Web and Notes Client and made it possible to add LotusScript to the formerly „Web only“ events „OnLoad“, „OnChange“, „OnBlur“, etc. via a dropdown.

You can read more about this here:

onLoad

Note: New for Formula and LotusScript with Release 6

So your place is totally ok though a „classic“ Notes developer would really choose „PostOpen over OnLoad (or QueryOpen in some cases)...