SNTT - Calling an agent using RunOnServer when saving a new document
Enough of the politics, let's have even more RunOnServer fun! Let's say that when a user saves and closes a document you want to update the newly saved document with information from an agent. RunOnServer takes a NoteID so it looks like a no brainer. In reality it proved to be more a little more difficult.
The first hurdle: I started out using the QuerySave event and the NoteID was always 0. I dug into the Notes.NetdeveloperWorks Notes forum and learned that the NoteID doesn't exist until the document is saved to the hard drive. Okay, I'll use the PostSave event. Since it's called "PostSave" I expected the document to be saved to disk. Well, either it isn't or the PostSave event occurs before the NoteID is populated. The solution: force the document to save from PostSave. I'm not sure why this forced save is necessary, but it works. Calling doc.Save from QuerySave gave a save conflict warning, but calling it from PostSave doesn't.
Sub Postsave(Source AsNotesuidocument) Dim session AsNewNotesSession Dim db AsNotesDatabase Dim agent AsNotesAgent Dim doc AsNotesDocument
Call Source.Document.Save(True,False) Set doc = Source.Document Set db = session.CurrentDatabase Set agent = db.GetAgent("Process Service Fees")
If agent.RunOnServer(doc.NoteID) <> 0 Then Msgbox"There was an error and the service fee notice was not sent.", 48,"Service Fees" EndIf EndSub
This LotusScript was converted to HTML using the ls2html routine, provided by Julian Robichaux at nsftools.com.