Solved

ComputeWithForm error

Posted on 2009-07-14
5
1,360 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 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