Notes Agent

i have a form button that when click, it calls an agent. however, in order for the agent to run, i have to save the new document so that the Note ID will be generated. Is there a way to generate a Note ID (not the universal ID) even if the document is not yet saved?

I use agent.parameterdocid in my agent to make sure that the agent runs on the specified notes document.

Subject: Notes Agent

Paul,

If you are going to use Note ID to reference the doc, then it has to be saved because that approach works on back-end documents.

Can’t you access the current on screen doc via NotesUIDocument and scrap the whole Note ID approach?

Ken

Subject: RE: Notes Agent

ken,

thanks for your reply.

i can’t access the on screen doc via NotesUIDocument because the agent being called uses NotesDocument’s db.GetDocumentByID (agent.parameterdocid) method. do you have any idea how can i access the on screen uidoc using its universalid so that i don’t have to save the uidoc.?

thanks

Subject: RE: Notes Agent

There is no way to do that. You still haven’t explained why you can’t use uidoc.Document. You’ve just stated that you’re using a different method, not explained why you can’t use the method suggested.

Subject: RE: Notes Agent

here’s the process: i have a button named “Generate” (see code below), on a notesuidocument, when clicked, this button calls the agent named “create doc for as400” (see code below). the agent’s function is to fetch a record to as400 based on the notesuidocument field values and NoteID, and updates the notesuidocument.

my questions are, First, how can i use the universalID rather than the NoteID so that i don’t need to save the document?

Second, by using the NoteID i was able to fetch the record and updated the values of the notesuidocument however, the updates cannot be viewed after using uidoc.refresh/uidoc.reload while the notesuidocument is still open. do you any suggestions on this?

thank you

Generate button :

Sub Click(Source As Button)

Dim uidoc As notesuidocument

Dim doc As notesdocument	

Dim s As NotesSession

Dim db As NotesDatabase

Dim dcol As notesdocumentcollection	

Dim ws As New notesuiworkspace

Dim agent As NotesAgent	



Set S = New NotesSession

Set db=s.Currentdatabase

Set uidoc = ws.currentdocument

Set doc = uidoc.document

Set agent = db.GetAgent("create doc for as400")		



Call uidoc.Save 



If agent.RunOnServer (doc.NoteID) = 0 Then

	Messagebox "Agent ran",, "Success"

Else

	Messagebox "Agent did not run",, "Failure"

End If

End Sub

“create doc for as400” agent script:

Sub Initialize

Dim con As New ODBCConnection

Dim qry As New ODBCQuery

Dim result As New ODBCResultSet

Dim msg As String

Dim s As NotesSession

Dim db As NotesDatabase		

Dim doc As NotesDocument

Dim agent As notesagent



Set S = New NotesSession

Set db=s.Currentdatabase

Set qry.Connection = con

Set result.Query = qry	



Set agent = s.CurrentAgent

Set doc = db.GetDocumentByID (agent.parameterdocid)





If Not	con.ConnectTo("cf","visualb","malayan") Then

	Msgbox "cannot conect"

End If		



qry.SQL = "SELECT * from motorcar.cf where lcode='" & doc.lcode(0) & "' and iucode=" & doc.iucode(0) & " and polrcyr=" & doc.polrcyr(0) & " and polrcno=" & doc.polrcno(0) & " and lossno=" & doc.lossno(0) & ""	



result.Execute

result.LastRow

numcol = result.NumColumns 

numrow=result.NumRows



If numcol=0 Then

	Exit Sub

End If		



For i = 1 To result.NumRows

	

	result.CurrentRow = i						

	

	Doc.assured = result.GetValue(14)

	Doc.unit = result.GetValue(22)	+ " " + result.GetValue(23)		

	Doc.plate = result.GetValue(28)		

	Doc.placeloss = result.GetValue(53)		

	Doc.dateacc = result.GetValue(54)		

	

	Call Doc.Save (True, False)    				

	

Next	



result.Close(DB_CLOSE)	

con.Disconnect	

End Sub

Subject: RE: Notes Agent

Is “you can’t” a clear enough answer? You’ll need to save the document, and for a couple of reasons. First, there’s the NoteID problem, which you’ve already figured out. Second, you’re using RunOnServer – if the document hasn’t been saved, how the is the server supposed to get the values from a temporary memory object sitting on a remote workstation? The document needs to exist on the server, which means it needs to be saved.