Solved

ComputeWithForm error

Posted on 2009-07-14
5
1,277 Views
Last Modified: 2013-12-18
I am trying to refresh documents in the backend using lotusscript.  When I run the code below, I get the 'not saved' error returned for every document in the view.  Whereas when I run the formula equivalent '@Command([ToolsRefreshSelectedDocs]) on the same set of documents, no error is returned and the computed fields on the form are correctly looked up and recomputed.  The following is a script i picked up from the net and modified it a bit.  I am an absolute newbie on script -- quick help will be sincerely appreciated.

Also, as per the Agent Log, the agent seems to run on all documents in the database, even though the view has much lesser documents.  In the agent properties for Target, I have specified 'All documents in the database'.  But the only other option is 'new and modified documents', which is not an acceptable option in my case, as I need to refresh daily even the older documents.
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("Log_Refresh") 

	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(True, False) 

		Else

			Messagebox "Document " & doc.UniversalID & " was not saved" 

		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

Open in new window

0
Comment
Question by:naazdeboo
5 Comments
 

Author Comment

by:naazdeboo
ID: 24852375
Another quick observation:

On the documents that are saved with computwithform (i inserted another prompt there too), the dblookups are not refreshed.  However again when I run @Command([ToolsRefreshSelectedDocs]) on the same document, the dblookup formulas are refreshed.  Why is this happening?
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 24856942
Well, about the "why" this is happening: the documents are refreshed in two entirely different environments. In the front-end, you have all code working. But a back-end agent runs on the server, no UI, no user associated (yes, the server ID). Consequently, if there are documents in the views that YOU can see but the server can't (due to Reader fields, for example).  

It fully depends on the formula stuff you used. I cannot give you an example of other potential errors, but I'll know one when I see one.

Ah, one example: if you use @Environment functions, you have a problem, since a server agent runs in/with the environment of the server, so with the notes.ini of the server. But there must be more functions that behave differently.

Conclusion: ComputeWithForm is not the 100% equivalent of @Command([ToolsRefreshSelectedDocs])
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 24857321
@Command([ToolsRefreshSelectedDocs]) computes only field (default) formulas, whereas ComputeWithForm executes the default value, translation, and validation formulas.

So check Validation and Translation formulas.

Only scheduled agents are run with server access rights. All other agents are run with signer (last saver) access rights.
0
 
LVL 1

Accepted Solution

by:
quzzie earned 500 total points
ID: 24913965
mbonacis comment probably points to the problem.  You will have a field on the form somewhere that fails to correctly compute.  You need to isolate the fields.  You could check this by manually , visuallay checking each field - timeconsuming and easy to miss an error.

Copy the form to make sure you have a backup.  then edit the main form and delete the bottom half of the fields.  re-run the agent.  if it faisl you know the field with the error is on the top half.  If it works, you know it was in the bottom half.  Repeat this by then removing half of the fields in the section you know is the problem.  After 2 or 3 runs you will usually get your code down to the field you need.  

it's typically going to be things like a date field that does not compute to a date, or text in a numeric field,etc.

Oh, why are yo doing a delete doc ?  The code seems to read- get all docs in a view, and try to refresh the doc and whether it gets refreshed or not, delete the doc ?  the delete doc seems to be not need if all you wanna do is loop through and refresh.

0
 

Author Comment

by:naazdeboo
ID: 25337199
This is just to close the topic.  After a lot of struggle we never figured out why it was not working.  Restarted the form and view from scratch and it finally worked.

The code that worked was as follows.  Isn't much different from above. So i guess it was some error in the form.  Also now the manually run Agent - @Command([ToolsRefreshSelectedDocuuments] and the following agent both returned the same results.

I am not sure how to assign the points though.  guzzie was closest to a solution.  Help will be appreciated.

Apologies for the delay -- but I was waiting to analyse where the problem was, so that there could be some value-add on here.  No such luck.
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("Log_Refresh") 

	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

			Call doc.Save(False,False)

		End If

		Delete doc ' remove doc from cache (does not delete from database) 

		Set doc = docNext 

	Loop 

	

        'Refresh the view

	Call v.Refresh 

End Sub 

Open in new window

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now