Usability - Productivity - Business - The web - Singapore & Twins

doc.ComputeWithForm Revisited

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"
    Call doc.ComputeWithForm(false,false)
    doc.Form = oldForm
    This also allows you to ban evaluate() from your script code thus keeping LotusScript and @Formula strictly separate
  • None of the Form events are fired. So no LotusScript, JavaScript or @Fomula in Form events (QueryOpen, QuerySave etc.) execute. Is is @Formulas in fields only
  • 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.

Posted by on 02 November 2006 | Comments (3) | categories: Show-N-Tell Thursday


  1. posted by Anastasia on Tuesday 10 April 2007 AD:
    Wow! Great, your trick for using a special form worked! Yea! Ever since we upgraded the server to Domino 7, the computeWithForm was no longer working in my agent. Possibly because some fields were above other fields, altho it did work in Domino 6! This got my agents working again, AND cut the run time WAY down! Thanks!
  2. posted by Bob on Thursday 01 November 2007 AD:
    Good info! Here's a question I've recently struggled with. . .You have two forms: "Form A" for Notes Client and "Form A web" for Web Client, both with form aliases of "FormA". On the web, a "Form A web" button calls an agent which sets doc = s.DocumentContext and eventually calls doc.ComputeWithForm.

    Which form is used to compute with the doc?
  3. posted by sushant likhar on Friday 09 May 2008 AD:
    The computewithform did not work for computed field for me. Instead It worked when i deleted the field.