Hi Everyone. I’ve been using this forever but I noticed recently that it’s not really common knowledge.
Let’s say you have a Form Design and in it you have a Readers and Authors field. Now let’s also say that you create NotesDocuments for this Form Design in the back-end. The question is: How do you populate a field in LotusScript and turn that field into a READERS or AUTHORS if required.
Many use a famous trick called “ComputeWithForm” which is a method that belongs to the NotesDocument Object. In simple terms, a ComputeWithForm will evaluate the entire NotesDocument against the Form Design it’s associated with….i.e. If you have a Form with 50 Computed Fields that contain various @Formulas, a ComputeWithForm will evaluate each of those Formulas for your NotesDocument Object.
e.g.‘ VARIABLES Dim ss as New NotesSession Dim db as NotesDatabase Dim doc as NotesDocument ‘ CODE Set db = ss.CurrentDatabase Set doc = db.CreateDocument Call doc.ReplaceItemValue( “Form”, “FormAliasName” ) Call doc.ComputeWithForm( False ) Call doc.Save( True, True )
While this can do the job and save you a lot of coding, a ComputeWithForm can make your code terribly slow depending on how many fields and Computed Values are in the Form and how many documents you plan on computing. I’ve seen a ComputeWithForm take 2 seconds to evaluate 1 NotesDocument. In that time your code could’ve achieved the same goal and a lot more if you wrote your code to not use it. Anyways, moving on.
If you didn’t use ComputeWithForm, you would land up having an issue with Readers and Author Fields in your NotesDocument:
e.g.‘ VARIABLES Dim ss as New NotesSession Dim db as NotesDatabase Dim doc as NotesDocument ‘ CODE Set db = ss.CurrentDatabase Set doc = db.CreateDocument Call doc.ReplaceItemValue( “Form”, “FormAliasName” ) Call doc.ReplaceItemValue( “CurrentReaders”, “John Jardin/Ukuvuma” ) Call doc.ReplaceItemValue( “CurrentAuthors”, “John Jardin/Ukuvuma” ) Call doc.Save( True, True )
If you had to open the DocumentProperties for this Saved NotesDocument and in the Field Properties Tab click on CurrentReaders, you will see it’s a Normal Text Field. This can cause massive issues from an Access point of view.
To solve this problem, we turn to our ever faithful friend…….NotesItem. Using the NotesItem Object, you can set the Field Type in your code. See below Examples 1 and 2:
Set item = New NotesItem( doc, “CurrentReaders”, “John Jardin/Ukuvuma”, READERS ) Set item = New NotesItem( doc, “CurrentAuthors”, “John Jardin/Ukuvuma”, AUTHORS ) Set item = New NotesItem( doc, “CreatedBy”, “John Jardin/Ukuvuma”, NAMES )
Also, so you know, SSJS for XPages also has a NotesItem Object that you can use similar to what we’ve done here. I’m not sure about Example 2 though.
Until next time, happy coding