WebQuerySave agent and explicit save (Why not?)

Hey gang,

Why can’t I explicitly save the context document in a WebQuerySave agent?

1st, I know the Notes help doesn’t recommend it.

2nd, I realize that the WebQuerySave agent automatically saves the notesdocument once it has completed.

3rd, I know you can prevent a document from being saved by setting SaveOptions to “0”.

So to come back to my question, if I explicitly save the context document in the WebQuerySave agent, then set the document’s SaveOptions field to “0”…wouldn’t I prevent a dual save from occuring?

For example, my WebQuerySave agent would end like the following:

Call doc.Save(True, True)

doc.SaveOptions = “0”

Thanks in advance

Gaston

Subject: WebQuerySave agent and explicit save (Why not?)

For some reason, that simply isn’t possible. If you check the return value of the save call, you’d see that it returns false!

if doc.Save(True, True) then

Msgbox "Document saved: " & doc.noteID

else

Msgbox "Document NOT saved: " & doc.noteID

end if

Subject: RE: WebQuerySave agent and explicit save (Why not?)

Hi Morten,

Thanks for the reply, but it is possible, because my document does get saved and does return the proper noteID.

Just to confirm you do realize that I’m dealing with the WebQuerySave agent and that the “Msgbox” function doesn’t work in this context. You must use the “Print” function in order to return data to the WEB user.

Thanks,

Gaston

Subject: RE: WebQuerySave agent and explicit save (Why not?)

Well, allow me to explain!

The Msgbox DOES work in a WebQuerySave agent. The output of a messagebox goes to the server log. I didn’t want to put a Print in there, since it might ruin any other output/redirect made by your current code.

Are you telling me that the doc.save() returns True in your webquerysave agent? That is the first time I’ve heard of that. I realize that the noteID is being reported, that wasn’t the point of my code, though. I wanted to show you that a save in webquerysave context didn’t succeed. Maybe I didn’t explain myself well.

Subject: RE: WebQuerySave agent and explicit save (Why not?)

Hey Morten,

Well I got a first for you, because my save method does return true. After a few minutes of making a few additional tests, I discovered something interesting.

I wrote up the simplest WebQuerySave Agent which is the following:

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Dim s As New NotesSession

Dim doc As NotesDocument

Set doc = s.DocumentContext

If doc.Save(True, True) Then

Print “Document Saved”

Else

Print “Document NOT Saved”

End If

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

THE RESULTS: You were right, the save method returned false.

At this point I said to myself “What the heck is going on!”, because the save method in my real application did return true. After examining my initial script and a few tests, I discovered that simply adding the line doc.SaveOptions = “1” before calling the save, made my save method return True.

For example, the save method of the following script does return true (and the only difference with the previous script is the doc.SaveOptions = “1” line.

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Dim s As New NotesSession

Dim doc As NotesDocument

Set doc = s.DocumentContext

doc.SaveOptions = “1” '<<<<<<<< new line

If doc.Save(True, True) Then

Print “Document Saved”

Else

Print “Document NOT Saved”

End If

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Have any suggestions, ideas of what might be going on.

Thanks,

Gaston

Subject: Wow!

The fact that the SaveOptions setting changes the return code of an explicit notesDocument.save really surprises me.

Can you tell whether the document is actually being saved to the database, or the save return value falsly returns True. I rather suspect the latter, so an explicit save in a webquerysave agent is effectively ignored, which is my experience in the fiurst place.

Try something like:

doc.webSaveTime = now()

… prior to the save to determine time of save (which might also be determined from $Revisions)

Subject: RE: Wow!

Hey Morten,

Once again, thanks for your interest in this weird Notes behavior.

I did what you suggested and added a field called webSaveTime and set it’s value to now() in the WebQuerySave agent.

The result is that the document does get saved. If I look at the stored value in the “webSaveTime” field, it is exactly the same as the value stored in the “$Revisions” field.

By the way, these tests were made with a 6.0.3 client and server.

I’ve been dealing with Notes for many years and I’ve seen Notes behave in weird ways, but this one is right up there.

My intitial reason for this post was to try and figure out why Notes doesn’t recommend calling an explicit save in a “WebQuerysave” agent. I wanted to know this because I want to display a confirmation message to the web user that his or her document was successfully saved without any doubt. A lot of developers simply send a print output telling the user that the document was succesfully saved. This is not really valid, because the document hasn’t really been saved yet. If a “WebPOSTSave” event would exist, it would be great and solve my problem. Another strategy is to send a confirmation email using an “On New…” agent, but this is not really what I’m looking for.

Thanks,

Gaston