QuerySave Script Event - Woe is me :-'(

Hey All,

I have a querySave event defined below and it makes a call to a form function createHistoryEntry also defined below.

My problem is, eveytime I edit and close the form, it creates a conflict doc instead of creating the entry and saving. I thought that query save code executed before the doc was actually written to disk?

Thanks,

Shawn

Sub createHistoryEntry(prfDocument As NotesUIDocument)

' Created by Shawn Taylor on October 13, 2006. This sub tracks the document editors over time

' This will give people a reference as to who edited the document and when in case follow up or clarification is needed



' ________________________________________________________________________________________________________



' Edited on October 25, 2006 commented out the created on line in lieu of the edited on line in the first part of the

' if statement that determines the content of the current edit history.



' ________________________________________________________________________________________________________



' Create variables used for edit history	

Dim session As New NotesSession

Dim editHistory As String	

Dim currentEdithistory As String

Dim currentDoc As NotesDocument



Set currentDoc = prfDocument.Document



' prfDocument.EditMode = True ' open the doc for editing

' editHistory = prfDocument.FieldGetText("fieEditHistory") ' retrieve the current history

' prfDocument.FieldClear("fieEditHistory") ' clear the field of the current entry



editHistory = currentDoc.fieEdithistory(0)

currentDoc.fieEdithistory = "" ' clear the field of the current entry



If editHistory = "" Then  'Defines creating or editing and sets string accordingly

	' currentEdithistory = "Created on " + Date$ + " at " + Time$ + " by " + s.CommonUserName ' create the string we want in the creator field	

	currentEdithistory = "Edited on " + Date$ + " at " + Time$ + " by " + session.CommonUserName ' create the string we want in the creator field	

Else

	currentEdithistory = ",Edited on " + Date$ + " at " + Time$ + " by " + session.CommonUserName ' create the string we want in the creator field

End If	



editHistory = editHistory + currentEdithistory ' Make comma seperated string for edits field	

currentDoc.fieEditHistory = editHistory

' prfDocument.FieldAppendText("fieEdithistory", editHistory) ' Insert above string to field - fieBroEdit History

' prfDocument.Save ' save our edit history

' prfDocument.EditMode = False ' close the doc	

session.close ' close the session

End Sub

Sub Querysave(Source As Notesuidocument, Continue As Variant)

' The purpose of this event is to mark a new note with the readers field data required to web enable the PRF.

' That is accomplished by creating a variable of our custom data type 'ProblemReportForm' and executing the method

' setReaderfield.



' If the doc is not a new document, we then set a flag for notification based on field level changes that are visible to the customer

' and the current notification status.



' Declare session variables

Dim session As New NotesSession

Dim db As NotesDatabase

Dim currentPrfDoc As NotesDocument

Dim thisTrnaPrf As New ProblemReportForm

Dim serverName As NotesName



' Set session parameters

Set db = session.currentDataBase

Set currentPrfDoc = Source.Document

Set serverName = session.CreateName(Cstr(db.server))



' Here we are checking to see if a conflict document exists. If it does, we tell the user about the problem and exit the sub

If Source.Document.HasItem("$Conflict") Then

	Msgbox "This is a [Replication or Save Conflict] document.  Changes should only be made to the original document!  Call X300 if you need help.  "  

	Exit Sub

End If



' We are checking to see if hte document has been saved. If it has not been saved we web enable the document by setting

' the readers field with the customer ID, and our internal ID's

If ( currentPrfDoc.IsNewNote ) Then

	Call thisTrnaPrf.setReaderField(db, currentPrfDoc)

Else 

	If (currentPrfDoc.SendCustMail(0) = True) And (currentPrfDoc.EmailNotificationFlag(0) <> "False") Then

		currentPrfDoc.EmailNotificationFlag = "False"			

	End If

	

End If



' Call currentPrfDoc.Save(False, False) ' saves the changes

Call session.close ' end current session



' This function writes an edit stamp to the document

Call createHistoryEntry(source)

End Sub

Subject: QuerySave Script Event - Woe is me :cry:

It is of note, that if I comment out the createHistoryEntry I get the same result. So it is not that sub that is creating the problem. This sub was in the postSave but I moved it to QuerySave to try and avoid the conflict Doc. I am moving it back.

This just started happening and I am not sure why. Famous last words I know…

Shawn

Subject: RE: QuerySave Script Event - Woe is me :cry:

I put my change history code in PostSave event.Querysave is just before saving. i.e. when saving, fields such as rtf fields gets updated (refreshed) so you would want to track history Postsave than QuerySave.

Subject: RE: QuerySave Script Event - Woe is me :cry:

Another update:

This is the code that kills it.

	If (currentPrfDoc.SendCustMail(0) = True) And (currentPrfDoc.EmailNotificationFlag(0) <> "False") Then

		currentPrfDoc.EmailNotificationFlag = "False"			

	End If

	

End If



Call currentPrfDoc.Save(False, False) ' saves the changes

Subject: RE: QuerySave Script Event - Woe is me :cry:

It looks like your QuerySave code actually saves the document, which means when QuerySave completes and Notes tries to save the document itself, there’s a conflict.

QuerySave should never save the document … Let Notes do that automatically once QuerySave is complete.

Subject: RE: QuerySave Script Event - Woe is me :cry:

I commented out hte save and it is still happening. Funny thing. This database is a test copy of our production DB. I edited another document in another production DB this AM and got the same error. I stopped and started the server for good measure and got the same thing in this test DB.

This is extremely odd.

Thanks for any suggestions.

Shawn

Subject: RE: QuerySave Script Event - Woe is me :cry:

This was related to Document Locking. We have turned it off in the interim until we can adjust the code to make it work.

Shawn