Solved

ComputeWithForm error

Posted on 2009-07-14
5
1,292 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

863 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

20 Experts available now in Live!

Get 1:1 Help Now