Domino Code Fragment

Code Name*
Refresh Authors or Readers Fields Updated via LotusScript Back-end
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.144.189.177
Description*
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
Problem:
You have written a script (similar to the following sample) that updates Authors or Readers fields of
a newly created document via back-end methods. For the changes to take effect, however, you
must open the document in front-end and save it. Is it possible to have the changes take effect from
the script?

Sample Script (attached to a button action):

Sub Click ()
......

'--- Create of a new document

Set doc = db.CreateDocument
doc.Form = "MyForm"

' Fill Author and Reader Fields
doc.AuthorField = AuthorListNames 'String containing the list of authors names
doc.ReaderField = ReaderList 'String containing the list of readers names

Call doc.Save (True, True)

'Refresh the view from Back-End and Front-End to see the newly created document

ws.ViewRefresh
view.Refresh

End Sub

Solution:
There are several ways to have the updates take effect, without having to open and save the
document.

Option #1: Insure that the fields of type Authors and Readers are defined as "Computed" (and not
"Computed when composed"). Then, add the following line to the script, before saving the
document:

"Call doc.ComputeWithForm(True,False)"

The Modified Script:

Sub Click ()
......

'--- Create of a new document

Set doc = db.CreateDocument
doc.Form = "MyForm"

' Fill Author and Reader Fields
doc.AuthorField = AuthorList
doc.ReaderField = ReaderList

Call doc.ComputeWithForm(True,False)
Call doc.Save (True, True)

'Refresh the view from Back-End and Front-End to see the newly created document

ws.ViewRefresh
view.Refresh

End Sub


Option #2: After setting the field value, set the IsReaders property of the field to "True."

Option #3: Declare a NotesItem variable for the desired field using the New NotesItem method
and set the SpecialType argument to either READERS or AUTHORS. For example:

Dim item As New NotesItem( doc, "ReaderField", ReaderList, READERS)