Archives for the ‘LotusScript’ Category

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.

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:

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:

Some might use For Loops, or Do While Loops instead of While-Wend, which doesn’t matter, because the good news is that there is a simple method that can replace the above code:

Call NotesDocumentCollection.StampAll( “Status”, “Submitted” )

Update on 13th September 2011

Hi Everyone. Thanks to “Lars Berntrop-Bos” for pointing out the following:

In version 8.5, IBM introduced another Method called “StampAllMulti” which works on both a NotesDocumentCollection and a NotesViewEntryCollection.

This function lets you use a NotesDocument Object as a Data Template for your Collection. All data in fields created in the NotesDocument Data Template will be sent through to the documents in the NotesDocumentCollection.

It will look something like this:

Set NotesDocument = NotesDatabase.CreateDocument

With NotesDocument

.FieldOne = “Value One”

.FieldTwo = “Value Two”

End With

Call NotesDocumentCollection.StampAllMulti( NotesDocument )

Just 2 NOTES:

1. If the fields don’t exist in the Docs in the DocumentCollection, they will be created.

2. If the Data Types are not the same, the Data Type in your NotesDocument Data Template will take preference, and will overwrite the Data Type fields in the DocumentCollection.

In my previous post, I explained how you could stop a Front-End Document from Reloading if you’re working with a Back-End NotesDocument. In this post, there is a similar issue which occurs with NotesViews.

Let’s say you have a LotusScript Agent which currently loops through documents in a NotesView, and during this loop, new documents are created by users, which get automatically populated into this view whilst you are using it. This annoys me, because either I get errors when working with Doc Collections, or my indexes could possibly get screwed up. The reason documents will automatically get added or removed from this view, is because this View’s Properties could be set to Refresh its Index Automatically. I usually prefer this when creating NotesViews, as it means that the data in the views is always the latest and Real Time.

So, the question is……how can we then stop the Refreshing of the View when working with it in a LotusScript Agent? Simple. When you declare and set the NotesView Object…there is a Property called “AutoUpdate”, which is default to True. Simply set this property to “False” before working with the view. See below Example:

Sub Initialize

‘ VARIABLESDim ss As New NotesSession Dim db As NotesDatabaseDim view As NotesViewDim doc As NotesDocument

I’ve seen a few scenarios where a person, using LotusScript, uses the NotesUIDocument Object to return the Back-end Document. From there, the person will work with the back-end document and will want to close off the NotesUIDocument, but when performing the call NotesUIDocument.Close, the Systems asks if you want to save the NotesUIDocument.Now, in some cases this is correct, especially if you’ve not saved the NotesUIDocument as yet, but in other cases where you have already saved the NotesUIDocument , it will still prompt you when trying to close the UIDoc.

To stop this will require 1 extra line of code in your LotusScript:NotesUIDocument.AutoReload = False

So, your code will look as follows:

Dim ws as New NotesUIWorkspace
Dim uidoc as NotesUIDocument
Dim doc as NotesDocument