- El cliente Notes utiliza un agente del servidor.
- Si necesitamos hacer una conexión ODBC (por ejemplo) sólo son necesarios los Drivers en el servidor.
- Los métodos Agent.RunOnServer y Agent.Run aceptan el parámetro del NoteID
- El agente invocado desde el cliente Notes, se ejecuta bajo la seguridad del que firmó el agente en el servidor.
- El agente invocado desde navegador web, se ejecuta bajo la seguridad de la persona que inició dicho agente desde Web.
Ejemplo
Agente del Cliente
Sub Initialize
Dim sess As New NotesSession
Dim db As NotesDatabase
Dim agent As NotesAgent
Dim doc As NotesDocument
Dim item As NotesItem
Dim ParamDocID As String
Dim datasource, uid, pw, status As String
Set db = sess.CurrentDatabase
Set agent = db.GetAgent("db2conn")
Set doc = db.CreateDocument
Set item = doc.AppendItemValue("datasource", "SAMPLE")
Set item = doc.AppendItemValue("userid", "bmeaney")
Set item = doc.AppendItemValue("passwd", "ping")
Call doc.save(True, False)
ParamDocID = doc.Noteid
Call agent.RunOnServer(ParamDocID)
Set item = doc.GetItemValue("Status")
status = item.text
Call doc.remove(True)
End Sub
Agente del Servidor
Set db = sess.CurrentDatabase
Set agent = sess.CurrentAgent
NoteId = agent.ParameterDocID
Set doc = db.GetDocumentById(NoteId)
Set item = doc.GetFirstItem("datasource")
sdatasource = item.Text
Set item = doc.GetFirstItem("userid")
suserid = item.Text
Set item = doc.GetFirstItem("passwd")
spasswd = item.Text
If Not con.ConnectTo( sdatasource, suserid, spasswd) Then
nErrNum = con.GetError
strErrMsg = con.GetExtendedErrorMessage(nErrNum)
Messagebox nErrNum & " - " & strErrMsg
Set item = doc.AppendItemValue("Status", "Connect Failed")
Goto Terminate
Else
Messagebox "Connect was successful"
Print "Connect was successful"
Set item = doc.AppendItemValue("Status", "Connect Succeeded")
End If
con.disconnect
Otros Ejemplos
1. This agent runs the agent named "Agent to be run LotusScript."
Sub Initialize
Dim s As New NotesSession
Dim db As NotesDatabase
Dim agent As NotesAgent
Set db = s.CurrentDatabase
Set agent = db.GetAgent("Agent to be run LotusScript")
If agent.RunOnServer = 0 Then
Messagebox "Agent ran",, "Success"
Else
Messagebox "Agent did not run",, "Failure"
End If
End Sub
This is "Agent to be run LotusScript."
Sub Initialize
Dim s As New NotesSession
Dim agent As NotesAgent
Set agent = s.CurrentAgent
Dim db As NotesDatabase
Set db = s.CurrentDatabase
Dim memo As New NotesDocument(db)
memo.Form = "Memo"
memo.SendTo = s.UserName
memo.Subject = "Message from LotusScript agent"
memo.Body = "The agent is running as " & s.UserName
Call memo.Send(False)
End Sub
2. This agent runs the agent named "Agent to be run parameter LotusScript," passing it the NoteID of a newly created document.
Sub Initialize
Dim s As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim agent As NotesAgent
Set db = s.CurrentDatabase
REM Create document containing data to be passed
Set doc = New NotesDocument(db)
doc.TriggerUserName = s.UserName
Call doc.Save(True, False)
REM Start agent and pass NoteID of document
Set agent = db.GetAgent("Agent to be run parameter LotusScript")
If agent.RunOnServer(doc.NoteID) = 0 Then
Messagebox "Agent ran",, "Success"
Else
Messagebox "Agent did not run",, "Failure"
End If
End Sub
This is "Agent to be run parameter LotusScript." It accesses the passed NoteID through ParameterDocID, accesses the referenced document, and removes it.
Sub Initialize
Dim s As New NotesSession
Dim agent As NotesAgent
Set agent = s.CurrentAgent
Dim db As NotesDatabase
Dim doc As NotesDocument
Set db = s.CurrentDatabase
REM Get document used for passing data
Set doc = db.GetDocumentByID(agent.ParameterDocID)
REM Send mail containing passed data
Dim memo As New NotesDocument(db)
memo.Form = "Memo"
memo.SendTo = s.UserName
memo.Subject = "Message from LotusScript agent"
memo.Body = "The agent was started by " & doc.TriggerUserName(0)
Call memo.Send(False)
REM Delete document used for passing data
Call doc.Remove(True)
End Sub
|