doc.ComputeWithForm seems to be confusing for a lot of developers. The Designer Help states: Validates a document by executing the default value, translation, and validation formulas, if any are defined in the document form. No word about computed Fields. In Notes 4.6 they didn't work, which still can be a problem for some. Starting with R5 they compute even if sometimes it doesn't look like. Also some challenge and an odd behavior remains.
In a nutshell these are the facts you need to keep in mind when using doc.ComputeWithForm:
- For editable fields the Default, Input Translation and Input validation fields are executed. The Default formula is executed when the field does not exist in the document. Typically that is only the case for a new document, but can be true also when the item was removed through code or the field was added to a form later
- For computed fields the formula is executed
- For computed when composed fields the formula is executed if the item does not exist in the document (same rules apply as for the default formula)
- Computed for display formulas are NOT executed. Therefore any formula depending on a field value of a computed for display field will take the value as empty thus producing unexpected results
- Side effects in Formulas like FIELD xxx := or @SetProfileField are executed. @Commands are not. Also @DeleteDocument has no effect.
- Self referencing fields are problematic. A Formula like @if(@thisValue="";1;@ThisValue+1) results in values 2-4-6-8 etc. You might change your formula to this: @If(@ThisValue="";1;@IsDocBeingEdited;@ThisValue+1;@ThisValue) and use LotusScript to increment your counter manually
- @IsDocBeingEdited returns @False, so you can influence if a formula is executed in the UI or with ComputeWithForm. A standard blocker for fields would be: @if(@IsDocBeingEdited;"";@Return(@ThisValue)).
Memento: You can't use that for display only fields since they MUST compute when you open a form, while all other formulas don't compute in read mode (OK: Defaults for new fields compute [but are not saved] as does the Window title)
- You might want to use a special form to use with ComputeWithForm. There you can do all sorts of data massage without writing lengthy LotusScript code. The code snippet would look like this:
oldForm = doc.Form(0) doc.Form = "SpecialComputeForm"
doc.Form = oldForm
This also allows you to ban evaluate() from your script code thus keeping LotusScript and @Formula strictly separate
- When your field returns more than 15k of data the summary flag is not set, so you can't use it in a view column. This is a bug that has been reported as SPR# TNIT5EYJ9N. Didn't find it in any release notes yet.
That pretty much sums it up.