Home > Ask the Domino Experts > Domino Development Questions & Answers > How to make computed fields recalculate
Ask The Domino Expert: Questions & Answers
EMAIL THIS

How to make computed fields recalculate

Andre Guirard EXPERT RESPONSE FROM: Andre Guirard

Pose a Question
Other Domino Categories
Meet all Domino Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 20 December 2006
I have a Lotus Notes view, and I want to save each of the documents in the Lotus Notes view in order to update the fields using an agent and the following LotusScript code:
Sub Initialize 
' instantiate the notessession object 
Dim s As New NotesSession 
        
' declare object variables 
  Dim db As NotesDatabase 
  Dim v As NotesView 
  Dim doc As NotesDocument 
        
        
  ' instantiate objects         
   Set db = s.CurrentDatabase 
   Set  v = db.GetView("V_ENG") 
   Set doc = v.GetFirstDocument 
        
   Do Until doc Is Nothing 
                
  ' save the doc 
   Call doc.Save( False, False ) 
   Set doc = v.GetNextDocument(doc) 
   Loop 
        
  ' refresh the view 
  Call v.Refresh 
        
End Sub 

I am really stuck on this, so any help or advice would be greatly appreciated.



Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Domino Development
Can I create and copy Microsoft Excel spreadsheets with LotusScript?
'Illegal circular use: Audit Trail' error when opening Lotus Notes docs
Sending and logging faxes from Lotus Notes and Domino
Accessing documents in a Lotus Notes database
Adding an action to the Lotus Notes right-click menu
Writing temporary text files that email as attachments
Trapping the on-click event of a radio button
Copying a form object using LotusScript
Connecting to a remote DB2 server with LEI
Lotus Notes' document check-in/check-out functionality

Lotus Notes Domino Formula Language
View hidden fields on Lotus Notes/Domino forms
Case-insensitive @Unique version combines fields on Lotus Notes forms
Do I use Formula or LotusScript to include a doclink to a Notes view?
Top 10 Lotus Notes/Domino coding and development tips of 2008
Provide rich-text formatting via the Profile document and Formula
Top 10 Formula language tips
Using Formula language code to sort Lotus Notes messages by subject
How to create dynamic JavaScript in Notes Domino without formulas
Stop response documents from showing in a Lotus Notes form
Formula language button manages Deny Access list searches

LotusScript
LotusScript agent parses ACL to Microsoft Notepad
LotusScript finds the first occurrence of a string from the right
Clear Recent Contacts view and prevent repopulation in Lotus Notes 8.x
Search Microsoft Active Directory with LotusScript
Three steps to trap and handle save conflicts with LotusScript
Troubleshoot agents by displaying LotusScript variables online
LotusScript sorts lists alphabetically
Run or restart Notes/Domino agents via text messages
LotusScript code rebuilds corrupted busytime.nsf file
Soft-code item names to facilitate LotusScript management

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


When Notes/Domino developers say they want to "update the fields" in a Lotus Notes view, they usually mean that they want to cause computed fields to recalculate. Assuming this is what you have in mind, you don't need an agent -- you can do it by creating a toolbar icon or view action that uses the formula @Command([ToolsRefreshSelectedDocs]). Select the documents you want to update and click this icon.

Although the LotusScript was unnecessary in this case, it does give me an excuse to lecture about useful principles of LotusScript programming, so listen up.

First, you should know that the back-end methods (NotesDocument.xxx) pay no attention to the form whatsoever. Using LotusScript or even a Formula agent, you can assign any field with any value -- even the totally wrong datatype, or even make up and assign fields that are not even on the form. Lotus Notes will not complain, nor will it change the values of any other fields that you did not explicitly set, even if they are computed fields based on the field you changed. The form is only used when you edit the document on-screen -- at other times it is ignored (with one exception I describe below).

The nice part is that this gives you total control; the downside is that sometimes you want these things done for you!

To get the fields to compute when you're not editing the document, use the NotesDocument.ComputeWithForm method. You can call this method to compute all the computed field formulas, input translations and validations, and update the document accordingly. Take care using this in a server agent, however, because it may fail for formulas that assume they're running on a Lotus Notes client (e.g., that use @UserName or try to @DBLookup in databases on a different server (which would require the current server to be "trusted" by the remote server) .

Also, if you're updating documents in a view, it's best to use view.AutoUpdate = False to prevent the view being refreshed every time you save a document. Not only is this slow, it can make you lose track of your position in the view. It will make the document you were just working on move to a different spot in the view, because of the changes you made to its fields.

In addition, any time you write a LotusScript agent that handles a lot of documents, use the Delete statement to remove documents from memory after you're done with them. Otherwise, you're filling up your available memory with cached documents.

So the resulting code would look something like this:

Sub Initialize 
Dim s As New NotesSession 
        
' declare object variables 
Dim db As NotesDatabase 
Dim v As NotesView 
Dim doc As NotesDocument 
Dim docNext As NotesDocument 
        
' instantiate objects         
Set db = s.CurrentDatabase 
Set  v = db.GetView("V_ENG") 
v.AutoUpdate = false 
Set doc = v.GetFirstDocument 
        
 Do Until doc Is Nothing 
 set docNext = 
v.GetNextDocument(doc) 
If doc.ComputeWithForm
(True, False) Then 
 Call doc.Save( False, False ) 
Else 
 ' a validation formula failed; 
I don't know what you would want to do here. 
                End If 
                Delete doc ' remove doc from cache 
(does not delete from database) 
                Set doc = docNext 
        Loop 
        
        ' refresh the view (don't bother) 
        ' Call v.Refresh 
End Sub 

Do you have comments on this Ask the Expert Q&A? Let us know.

Related information from SearchDomino.com:

  • Learning Guide: Formula language
  • Learning Guide: LotusScript
  • FAQ: LotusScript
  • FAQ: Formula language
  • Reference Center: LotusScript tips and resources
  • Reference Center: Formula language tips and resources




  • Search and Browse the Expert Answer Center
    Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
    Browse our Expert Advice



    Lotus Notes Domino on Blackberry and mobile devices
    HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
    About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
    SEARCH 
    TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

    TechTarget Corporate Web Site  |  Media Kits  |  Site Map




    All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
      TechTarget - The IT Media ROI Experts