Situation:A user comes in and creates a new document through a form (notes client). It is a new form and does some validation and then ultimately it is saved using a button and the “@Command([FileSave])”. I have some basic validation and notifications contained in the “QuerySave” event. If the querysave event is successful, I have some more code that is in the Post Save event to trigger an agent which uses the “runonsever” method in lotusscript.
Problem:
The validation works and the notification are sent via the querysave event. The post event is triggered and the runonserver method is used to call the agent. All good. When the agent runs on the server the first time, I get an error saying “Error 4270 on line 24 in function INITIALIZE: Invalid note id”. THis is the line in the server agent code that references the notesid. Now if I take the same document (not new) and go into edit mode and resave it, the agent is triggered again and it works. It’s like the document can not be found when first created. Any ideas? here is some code below:
End of the QuerySave event:
'Set sendflag field to yes
doc.SendFlag="Yes"
'Save document
SaveNow:
Continue=True
JustSaved="YES"
Call Source.Close
Exit Sub
End Sub
PostSave event reads:
Sub Postsave(Source As Notesuidocument)
Dim sess As New NotesSession
Dim db As notesdatabase
Dim doc As notesdocument
Dim TheAgent As NotesAgent
Set db=sess.currentdatabase
Set doc = source.Document
If doc.FileCreationDate(0)="" And JustSaved="YES" Then
Set TheAgent=db.GetAgent("Date Change - File Creation")
Call TheAgent.RunOnServer(doc.NoteID)
End If
End Sub
Finally the runonserver agent:
Sub Initialize
Dim sess As New NotesSession
Dim agent As NotesAgent
Set agent = sess.CurrentAgent
Dim db As NotesDatabase
Dim doc As NotesDocument
Set db = sess.CurrentDatabase
Set doc = db.GetDocumentByID(agent.ParameterDocID)
Error happens at the line above but does not error if I take the same doc and resave.