Hi,
I have a database with over 3000 documents. I want to run an agent every night that refresh some fields on all documents. There are 5 computed fields that I want to refresh.
I have tried with this code:
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim success As Variant
Dim Counter As Integer
Set db = session.CurrentDatabase
Set view = db.GetView("AllDocuments") ' Get the all the docs in the view called ViewName
Set doc = view.GetFirstDocument ' Get the first document in the view
Counter = 1
While Not (doc Is Nothing) ' Continue while there is a document available
Messagebox Counter
success = doc.ComputeWithForm (False, False) ' Refresh the document - updates computed fields
If success Then ' ComputeWithForm method returns true if there are no errors during refresh
Call doc.Save (True, True) ' Save document to disk
End If
Counter = Counter + 1
Set doc = view.GetNextDocument(doc) ' Get next document in the view
Wend
But it takes to long time. (Over 6 hours)
How do i do to just refresh this 5 computed fields and not the rest of the document?
Best Regards
Henrik
Subject: ComputeWithForm but only on some fields
one possible solution could be this:
a. create a seperate form which will contain only those fields which you want to compute
b. before calling ComputeWithForm method Form field of document to new form name i.e.
doc.form = “newformname”
c. now call doc.computeWithForm
d. change back Form field to original name i.e.
doc.form = “originalform”
e. save the document
Please note that for the new form if computed fields are based on other fields, those must be present with appropriate values before calling compute with form.
HTH
Subject: RE: ComputeWithForm but only on some fields
Thanks for your reply!
This is my code after the change. Is this what you mean?
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim success As Variant
Set db = session.CurrentDatabase
Set view = db.GetView("AllDocuments") ' Get the all the docs in the view called ViewName
Set doc = view.GetFirstDocument ' Get the first document in the view
While Not (doc Is Nothing) ' Continue while there is a document available
doc.form = "tmpNyPost"
success = doc.ComputeWithForm (False, False) ' Refresh the document - updates computed fields
doc.form = "Ny Post"
If success Then ' ComputeWithForm method returns true if there are no errors during refresh
Call doc.Save (True, True) ' Save document to disk
End If
Set doc = view.GetNextDocument(doc) ' Get next document in the view
Wend
My new form is ofcourse called tmpNyPost. This code is as slow as the code before.
Best Regards
Henrik
Subject: RE: ComputeWithForm but only on some fields
yes, you are doing correct. Tell me how many computed fields are there on tmpNyPost form?
Subject: RE: ComputeWithForm but only on some fields
There are only 5 of them…
Subject: RE: ComputeWithForm but only on some fields
hmmm…shouldn’t take this much time as ComputeWithForm is directly related to number of fields on a document. anyways try this formula in an action button on a view:
@Command( [ToolsRefreshAllDocs] )
Sorry: this above command cann’t be used in Scheduled agents
Subject: RE: ComputeWithForm but only on some fields
Thats not possible. Because, this agent i scheduled to go every night…
Subject: RE: ComputeWithForm but only on some fields
Computewithform is a very expensive method - you’re probably better off just doing the calculation for the fields in lotusscript. That way you can even check whether the new value is different from the old value. If none of the values change you don’t even need to call a save for the doc. I’m pretty sure that would be much quicker than using computewithform
Dan