Domino 9 und frühere Versionen > Entwicklung
Dokument des Agenten greifen
Glombi:
Mit dem Agenten ginge es auch so: Wenn Du den Agenten aufrufst, kannst Du die Doc-ID mitgeben. Diese kannst Du dann im Agenten abfragen: Dazu gibt es die Methode
agent.ParameterDocID
Übergabe der DocID an Agenten:
call agent.Run(doc.NoteID)
Beispiele aus der Hilfe:
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.Run(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
Andreas
Semeaphoros:
Die Hilfe ist allerdings da etwas ungenau. Wenn man unter ParameterDocID nachschaut, steht da folgendes:
Read-only. Returns the NoteID of a document passed to the agent by Run or RunOnServer.
..... würde eigentlich heissen, dass man das DOCUMENT und nicht die DocID als Parameter übergeben müsste .... Was ist da richtig? Das Beispiel oder die Beschreibung ???
Uebrigens erst ab 5.0.2
Ata: Profildokumente sind spätestens ab R4.6 sehr zuverlässig. Unter 4.1, als sie eingeführt wurden, waren sie tatsächlich sehr "flaky", replizierten nicht immer und haben auch sonst noch so ein paar Sprünge gemacht, aber unterdessen sind Deine Befürchtungen unbegründet.
shizen:
Hallo
aus dem bisherigen hab ich mir folgendes zusammengebastelt:
es funzt sowiet fast, aber bei Call rtitem.AppendRTItem(doc.Body) kommt ein Mismatch und ich kann mir nicht vorstellen warum? :-[ :-[ :-[
Dim NotesColl As NotesDocumentCollection
Dim session As New NotesSession
Dim mailbox As New NotesDatabase("","")
Dim current As NotesDatabase
Dim maildoc As NotesDocument
Dim rtitem As NotesRichTextItem
Dim dummy As Variant
Dim i As Integer
Dim doc As NotesDocument
Dim sendto As String
Dim sendas As String
Dim subject As String
Set NotesColl=session.CurrentDatabase.UnprocessedDocuments
If NotesColl.count>0 Then
Set doc=notescoll.GetFirstDocument
For i = 1 To NotesColl.count
sendas="CN=Agent/O=lwb"
sendto=doc.subject(0)
subject=doc.From(0)
' get handle to mail.box on the users current mail server
Set current = session.CurrentDatabase
Call mailbox.Open( current.server, "mail.box" )
' Create a new document in the severs mail box
Set maildoc = mailbox.CreateDocument
maildoc.Form = "Memo"
maildoc.From = sendas
maildoc.SendFrom = sendas
maildoc.SendTo = sendto
maildoc.Recipients = sendto
maildoc.Subject = subject
Set rtitem = maildoc.CreateRichTextItem("Body")
Call rtitem.AppendRTItem(doc.Body)
maildoc.PostedDate = Now()
maildoc.ComposedDate = Now()
maildoc.DeliveredDate = Now()
maildoc.Principal = sendas
maildoc.EncryptOnSend = False
Call maildoc.Save( True, False )
Set doc=notescoll.GetNextDocument(doc)
Next i
End If
Glombi:
Das Call rtitem.AppendRTItem(...) verlangt ein RichTextItem als Parameter.
Also
dim bodyrtitem as NotesRichTextItem
Dim NotesColl As NotesDocumentCollection
Dim session As New NotesSession
Dim mailbox As New NotesDatabase("","")
Dim current As NotesDatabase
Dim maildoc As NotesDocument
Dim rtitem As NotesRichTextItem
Dim dummy As Variant
Dim i As Integer
Dim doc As NotesDocument
Dim sendto As String
Dim sendas As String
Dim subject As String
Set NotesColl=session.CurrentDatabase.UnprocessedDocuments
If NotesColl.count>0 Then
Set doc=notescoll.GetFirstDocument
set bodyrtitem = doc.GetFirstItem("Body")
For i = 1 To NotesColl.count
sendas="CN=Agent/O=lwb"
sendto=doc.subject(0)
subject=doc.From(0)
' get handle to mail.box on the users current mail server
Set current = session.CurrentDatabase
Call mailbox.Open( current.server, "mail.box" )
' Create a new document in the severs mail box
Set maildoc = mailbox.CreateDocument
maildoc.Form = "Memo"
maildoc.From = sendas
maildoc.SendFrom = sendas
maildoc.SendTo = sendto
maildoc.Recipients = sendto
maildoc.Subject = subject
Set rtitem = maildoc.CreateRichTextItem("Body")
Call rtitem.AppendRTItem(bodyrtitem)
maildoc.PostedDate = Now()
maildoc.ComposedDate = Now()
maildoc.DeliveredDate = Now()
maildoc.Principal = sendas
maildoc.EncryptOnSend = False
Call maildoc.Save( True, False )
Set doc=notescoll.GetNextDocument(doc)
Next i
End If
Glombi:
--- Zitat von: Semeaphoros am 12.11.03 - 16:53:21 ---Die Hilfe ist allerdings da etwas ungenau. Wenn man unter ParameterDocID nachschaut, steht da folgendes:
Read-only. Returns the NoteID of a document passed to the agent by Run or RunOnServer.
..... würde eigentlich heissen, dass man das DOCUMENT und nicht die DocID als Parameter übergeben müsste .... Was ist da richtig? Das Beispiel oder die Beschreibung ???
--- Ende Zitat ---
So wie in den Beispielen.
Andreas
Navigation
[0] Themen-Index
[#] Nächste Seite
[*] Vorherige Sete
Zur normalen Ansicht wechseln