Subject: RE: copy value to field
Silly fella – it’s LotusScript, but it’s using a whole bunch of undeclared Variant variables instead of addressing the Items of the Document or the Fields of the UIDocument. It likely runs perfectly, but since it’s a no-op, nothing appears to happen unless the debugger’s open.
To the OP:
In Formula Language, one simply uses the name of the field. Not so in LotusScript. LS accesses the elements of a Notes database through a hierarchy of objects. When you create an action, for instance, it starts out like this:
Sub Click(Source As Button)
End Sub
Those lines are important, since they tell Notes where the code is attached and how it is to be called. In this case, it is code called when the associated button is clicked.
Now you need to get and set the field values. You cannot get to the fields directly – you need to go through the container (the document), and you need to make your way TO the document before you can start looking for fields. There are two “free” objects that you can always access in the Notes client – the NotesSession and the NotesUIWorkspace. From them, you can get anywhere else you need to go. In this case, you need to get to the currently-opened document:
Sub Click(Source As Button)
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Set uidoc = ws.CurrentDocument
Set doc = uidoc.Document
End Sub
You can access values directly from the uidocument, but they will always be a single text string. Using the document rather than the uidocument means that multiple values will be separated out, and that the values will (usually) be of the correct data type.
You can access the fields in several ways. From the document, you can use the GetItemValue method, or you can use the “extended class syntax” which allows you to treat the fields as if they were properties of the document object. I prefer the former syntax for a number of reasons:
value = doc.GetItemValue(“FieldName”)
but others are more at home with the extended class syntax:
value = doc.FieldName
BIG NOTE: The values in a NotesItem (the back-end object that represents a field on a form) is ALWAYS an array, even if it only contains one value. You need to keep that in mind when reading a field. So, in order to examine a single value in a field, you need to read a single member of the array:
value = doc.GetItemValue(“FieldName”)(0)
To put a value into a field:
Call doc.ReplaceItemValue(“FieldName”, value)
or
doc.FieldName = value
No matter which syntax you use, you can only assign the ENTIRE value of a field all at once – you can’t simply change one value in a multi-value field.