Runonserver and Error - Invalid note id

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.

Subject: Runonserver and Error - Invalid note id

The noteid is related to the position within the database that the document is stored.

I think that you are correct in that this is not being reflected back to the NotesDocument object in the initial PostSave.

Try re-retrieving the document first, making sure that the cached copy is cleared.

i.e.

Sub Postsave(Source As Notesuidocument)

Dim sess As New NotesSession

Dim db As notesdatabase

Dim doc As notesdocument

Dim TheAgent As NotesAgent

Dim docId as String

Set db=sess.currentdatabase

Set doc = source.Document

If doc.FileCreationDate(0)=“” And JustSaved=“YES” Then

docId = doc.UniversalId

delete doc

Set doc = db.getDocumentByUNID(docId)

Set TheAgent=db.GetAgent("Date Change - File Creation")

Call TheAgent.RunOnServer(doc.NoteID)

End If

End Sub

Subject: RE: Runonserver and Error - Invalid note id

That did it. Thank you Andrew… much appreciated