Wednesday, September 22, 2021

Checkbox: allow entries not on list [client]

 I love working in the Notes client. So much is handled right off. As part of a personal research project, I have been categorizing references from a variety of sources. The easiest way is a checkbox, of course. This does leave something out- the ability to add in a new category on the fly. Dialog Lists have an option for new entries that is very handy. There is not an out of the box way to do this with checkbox fields. And that is what I needed. 

So I created a text field I could put new categories in, naming it "newCat". In the Terminate event, I wrote the value to the field. As I populated the checkbox with a category view, as of then, my new category is available. Below is my code

Sub Terminate
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Set uidoc = workspace.CurrentDocument

If Len(uidoc.FieldGetText("newCat")) > 1 Then
Call uidoc.Save
Set doc = uidoc.Document

Dim newCatVar As Variant
Dim arrApp As Variant

newCatVar = Split(uidoc.FieldGetText("newCat"), ",")

Dim getArray As Variant
Dim itemarray As NotesItem
Set itemarray = doc.GetFirstItem("Categories")
getArray = itemarray.Values
arrApp = Arrayappend(getArray, newCatVar)
Call doc.ReplaceItemValue("Categories", arrApp)
Call doc.RemoveItem("newCat")
Call doc.Save(True, False)
End If
End Sub