Hi all,
I had a great Action Button, but then realised that normal users would not have access to open other databases to create a document.
So I read about invoking an Agent to RunOnServer. This should then use the Agent Signers authority.
However, I cannot debug the agent. Probably as it runs on the server rather than in the client.
Please could somebody tell me why the agent is not doing anything, or how to debug it in some way.
Basically, the Appointment is created & on Saving the agent needs to loop through names in a field, find a database, open it, then create a document in the database, based on info from the appointment document.
This all worked as an Action, so it must be the way the document info is being passed to the agent.
Action Button
Sub Click(Source As Button)
'Set Dimensions
Dim session As New NotesSession
Dim workspace As New NotesUIWorkspace
Dim db As NotesDatabase
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim agent As NotesAgent
'Get Current Document to work on
Set uidoc = workspace.CurrentDocument
Set doc = uidoc.Document
'Save current document
Call doc.Save(True, False)
'Start agent and pass note ID of doc
Set db = session.CurrentDatabase
Set agent = db.GetAgent("Agent Code")
Call agent.RunOnServer(doc.NoteID)
'Save current document
Call uidoc.Save
Call uidoc.Close
End Sub
Agent Code
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim doc1 As NotesDocument
Dim doc2 As NotesDocument
Dim item As NotesItem
Dim agent As NotesAgent
Set agent = session.CurrentAgent
Set db = session.CurrentDatabase
'Get document used for passing data
Set doc = db.GetDocumentByID(agent.ParameterDocID)
'Run Loop through any names in AlarmDialog Field
Forall n In doc.AlarmDialog
'Get current NAB
Dim nab As NotesDatabase
Set nab = session.GetDatabase("Spinoza" , "names.nsf")
'Get view in NAB
Dim view As NotesView
Set view = nab.GetView("($Users)")
'Find person in view
Set doc1 = view.GetDocumentByKey( n, True)
'Find mailfile field value from document
homeserver = doc1.GetItemValue("mailserver")
mailfile = doc1.GetItemValue("mailfile")
'Get database to create document in
Set db = session.GetDatabase( homeserver(0) , mailfile(0))
'Create mini-doc
Set doc2 = New NotesDocument(db)
Set item = doc.GetFirstItem("$Alarm")
Call item.CopyItemToDocument(doc2, "$Alarm")
Set item = doc.GetFirstItem("$AlarmOffset")
Call item.CopyItemToDocument(doc2, "$AlarmOffset")
If doc.HasItem("RepeatDates") Then
Set item = doc.GetFirstItem("RepeatDates")
Else
Set item = doc.GetFirstItem("CalendarDateTime")
End If
Call item.CopyItemToDocument(doc2, "CalendarDateTime")
Call item.CopyItemToDocument(doc2, "PostedDate")
Set item = doc.GetFirstItem("Subject")
Call item.CopyItemToDocument(doc2, "Subject")
'Save and move mini-doc to folder
Call doc2.Save(True , False , True)
Call doc2.PutInFolder ("($Alarms)")
End Forall
'Delete document used for passing data
Set db = session.CurrentDatabase
Call doc.Remove(True)
End Sub