The ComputeWithForm Method has been around for a quite a while and can be very useful. However, I've often had the need to compute just a field or two on a very complex form, and this can cause problems in workflow if the entire form isn't filled out yet and validation somewhere else on the form might fail.
For example, sometimes appending text into a multi-value computed field requires the field to be recomputed before Notes can recognize it as an array. A simple solution is to create a VERY basic form with just the fields that you want to re-compute. Switch forms in your code, call the ComputeWithForm method and switch the form back. This method returns a flag which you can then check to see if the compute was successful. If computeSuccess is = True, then there are no errors on the document and the fields passed validation. If not, you could go into some type of error handling routine.
Keep in mind this will not work if there is a form stored in the document. For this method Notes determines the form for the document by:
1. The stored form, if any
2. The contents of the Form item
3. The database default form, if there is not a Form item
Check the Help documention for this method for explanations on the method parameters.
Get a handle ndoc on your document ndoc.form = 'ComputeFormName' Call ndoc.save(True, False) computeSuccess = ndoc.ComputeWithForm(False, False) ndoc.form = 'OriginalFormName' Call ndoc.save(True, False)
In his development tip titled, The ComputeWithForm Method, Timothy Neyman gives a technique that uses ComputeWithForm after substituting a different, shorter form, to avoid recalculating all fields.
However, the code sample shows the form being saved twice. Any time you've saved by computing with a short form is going to be more than used up by saving the document a second time. Therefore, the tip doesn't meet its stated goal.
It's not necessary to save the document before calling ComputeWithForm.
Note: ComputeWithForm is slow whether you have a complex form. If you really want to improve performance, forget using ComputeWithForm. Instead, individually calculate the required new field values in your LotusScript code.ndoc.form = 'ComputeFormName'
' DON'T Call ndoc.save(True, False)
computeSuccess = ndoc.ComputeWithForm(False, False)
ndoc.form = 'OriginalFormName'
Call ndoc.save(True, False)— Andre Guirard