Agent not running

I have this agent as an action within a form. It works fine.If I put this a the end of another agent (action button on form), it does not update my doc. Any suggestions why it would not update when inside that agent?

Set agent = db.GetAgent(“computewithformagent”)

---------here is the agent that works but does not work in the agent--------

Sub Initialize

Dim session As New NotesSession

Dim db As NotesDatabase

Dim workspace As New NotesUIWorkspace

Dim view As notesview

Dim uidoc As Notesuidocument

Dim doc As NotesDocument

Dim doc2 As NotesDocument



Set db = session.CurrentDatabase

Set uidoc = workspace.CurrentDocument

Set doc = uidoc.document

vyear = doc.CurrentYear

vloc = doc.PlantLocation

key = vloc



Set view = db.getview("Summary " & vyear(0))

Set doc2 = view.getdocumentbykey(key)

Call doc2.ComputeWithForm(False,False)

Call doc2.Save( True, True )

End Sub

Subject: agent not running

Are u calling the agent in the front end ?

“Set uidoc = workspace.CurrentDocument” - This line will work only when the form is opened. Its a front end class.

Raj

Subject: RE: agent not running

Originally that’s how it was setup. When I edit the doc then save the doc in the ui, the code runs and the docs are updated and the view shows correctly.

Yes, I’m trying to do that from the back end. I tried the code below and it does not work either. Actually, I need to grab 2 fields from the front end ( open document ) then when I hit the action button while in the document, let the code update the docs in the backend so the view shows up.

Sub Initialize

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("Summary 2006") ' 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

	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 

	

	Set doc = view.GetNextDocument(doc) ' Get next document in the view

Wend

End Sub

Subject: RE: agent not running

Loyd,

Use subs or functions in your action to accomplish the multiple steps.

You can save this in a script library or you can create a class in the script library. Either of these should get the job done. The library will more easily allow you to reuse the code in the future.

Shawn