Mysteries of QuerySave

I need to keep a copy of Before Image document before saving changes.I added the following script in Querysave event :

Sub Querysave(Source As Notesuidocument, Continue As Variant)

Dim session As New notessession	

Dim doc As notesdocument

Set doc=Source.document

            Dim db As NotesDatabase

Set db = session.CurrentDatabase



Dim doc3 As notesdocument

Dim olddoc As notesdocument



Set doc3 = New NotesDocument(db)

Set doc3 = db.createDocument()

	

unid$ = doc.UniversalID

Set olddoc = db.GetDocumentByUNID( unid$)

Call olddoc.CopyAllItems( doc3)



Call doc3.Save(True, False)

when I check the saved current document (doc) and the copy of the old one(doc3) the result is the same. I get the last version in both cases.

Is Lotus Notes has already saved the current doc when I execute the GetDocumentByUNID ?

Any idea ?

Subject: Mysteries of QuerySave

Jose,

Are you trying to make the doc3 object the previous version of the doc object? If so, this code will never work, because when you instantiate the doc object like you have above (set doc = source.Document) you are getting a copy of the document as it CURRENTLY resides in memory. That means any changes you have made will already be part of the doc object and your previous version has been effectively destroyed.

To accomplish what you are trying to do, you will need to create the copy during the queryopen or postopen event using a global variable that can move between the events. Later on, you can use the querysave event to find out if any changes have been made (usually by setting a hidden field on the form and checking it during the querysave) and then save the copy that exists in your global variable.

hope that makes sense.

brandt

Subject: RE: Mysteries of QuerySave

Thank you for your prompt answer.but I thought that at this step, the current doc wasn’t yet saved in DB and with “Set olddoc = db.GetDocumentByUNID( unid$)” I could get the before image of the current document.

it’s not correct …

Subject: RE: Mysteries of QuerySave

Jose,

It doesn’t matter for purposes of LS. Getting the document by UNID is still going to return the most recent version of the doc in memory. and that would be the changed doc. You need to get a handle on the doc before any changes are made and you need to copy the items into a completely different doc object because all doc objects are passed by reference, so if you don’t make the copy before the changes are made, you will still pass the changes on, which would effectively render your global document object useless.

brandt

Subject: RE: Mysteries of QuerySave

Hi,

thank’s a lot for your suggestion. I used a variant in global declaration where I copied the Before Image, and in Querysave, I created a response document with this variant.

And now it’s well running …

It removes me a thorn in the foot (or something like that)

Subject: RE: Mysteries of QuerySave

Hi,

Even I have the same issue, but mine is to save both the old one as archive and other one as current one. Any idea how to do this. The one before save is indeed a global variant. But funny part is both get saved and the archive one doesnt show in view. When I open, edit and just save again then it gets displayed in view. Am I missing something over here.

Subject: RE: Mysteries of QuerySave

Jose

I seem to remember you can get the last saved version of the document using view.getdocumentbykey(Cstr(doc.UniversalId),true)

The view will need to be keyed on @text(@DocumentUniqueID)

HTH

John

Subject: Mysteries of QuerySave

Why not use versioning?