Response Doc Not Updating When Open In UI

I’m working on a database that has a main document and several types of response documents. I have a button in a view. When a user clicks the button it should look to see if there is already a response document. If so, it should open that one. If one doesn’t exist, it creates a new one. This works fine. However, I’m having problems when I edit a response document. Here are the steps I’m doing when I see the problem:

  1. Create a main document.

  2. Click the button in the view to create a response document.

  3. Enter some info in the response document and save and close it.

  4. Use the same button again to bring up the response document and make changes to it.

  5. Use the button again to bring up the response document.

When I do step 5, it brings up a previous version of the response document that doesn’t include the changes I made in step 4. If I open the document normally by double-clicking it, the changes are there. If I look at the document properties, my changes are there. If I close out of the database, re-open it and use the button, the changes are there. If I switch views and go back, my changes are there. Why aren’t they there when I do step 5 right away? I’m running into problems with save conflict messages because it’s not opening the document as it currently exists in the database.

I thought it might be a caching issue with shared actions, so I moved the code to a regular action button in the view, but it does the same thing.

What is going on? Here’s my code. Any ideas are welcome! Thanks!

Const THISFORM = “frmSched2”

Dim ws As NotesUIWorkspace

Dim parentDoc As NotesDocument, childDoc As NotesDocument

Dim session As NotesSession

Dim db As NotesDatabase

Dim coll As NotesDocumentCollection, childColl As NotesDocumentCollection

Dim formNm As String

Dim formFound As Boolean

Const FLD_FORM = “Form”

Sub Click(Source As Button)

'If a sched2 already exists, open that, otherwise create a new one

'if running from view, need to get the currently selected document

'if running from within a doc, need to get details from uidoc

Set ws = New NotesUIWorkspace

Set session = New NotesSession

Set db = session.CurrentDatabase



Set coll = db.UnprocessedDocuments

If coll.Count = 0 Then 'must be running from within doc, not from view

	'running from within document

	Set ws = New NotesUIWorkspace

	Dim uidoc As NotesUIDocument

	Set uidoc = ws.CurrentDocument

	If uidoc.IsNewDoc Then   'if this is a new document they need to save it first

		Msgbox "You must save this main CE before you can create the attached schedules.",0+16,"Action Cancelled"

		Exit Sub

	End If

	Set parentDoc = uidoc.Document

	Call uidoc.Close

Else

	'running from the view

	Set parentDoc = coll.GetFirstDocument		

End If

'We now have the backend parent document. Look for an existing sched2. 

'If one exists open it. If not, create one and set it to be a response

'Find all the children and look for the form name

Set childColl = parentDoc.Responses

If childColl Is Nothing Then

	'there are no responses, just create a new one

	createNewResp

	Exit Sub

End If

Set childDoc = childColl.GetFirstDocument

If childDoc Is Nothing Then

	'there are no responses, just create a new one

	createNewResp

	Exit Sub

End If

While Not childDoc Is Nothing

	'get the form name, if it's a sched2, open it in edit mode,

	'if not sched2, get the next

	formNm = childDoc.GetItemValue(FLD_FORM)(0)

	If formNm = THISFORM Then

		'open it in edit mode

		formFound = True		

		Call ws.EditDocument(True,childDoc)

		Exit Sub		

	Else

		'do nothing, just get the next one to check

	End If

	Set childDoc = childColl.GetNextDocument(childDoc)

Wend



If formFound <> True Then

	'no response of the correct type was found so create a new one

	createNewResp

End If

End Sub

Sub createNewResp

Dim newResp As NotesDocument

Set newResp = db.CreateDocument

Call newResp.ReplaceItemValue(FLD_FORM,THISFORM)

Call newResp.MakeResponse(parentDoc)

'now open it for editing

Call ws.EditDocument(True,newResp)

End Sub

Subject: Response Doc Not Updating When Open In UI

Karen,

You are not saving the reponse document after your MakeResponse line

Mike

Subject: RE: Response Doc Not Updating When Open In UI

I don’t want to save it. I want to compose the new document and bring it up in the UI for the user to either fill in various fields, or close without saving as they see fit.

And when I go through my manual steps, I save the document. When I re-open the document, the changes are not there, even though they exist in the backend document and in the document’s properties. So the changes are saved, but it’s like the code is bringing up some old cached version of the document that’s still hanging out in memory, rather than bringing up the saved document with the changes.

Subject: RE: Response Doc Not Updating When Open In UI

Are you sure that step 5 is opening the existing document and not creating another new one??

Subject: RE: Response Doc Not Updating When Open In UI

Positive. There are field values populated from my initial change, but they just aren’t the latest set of changes I made. It’s the strangest thing I’ve ever seen.(well, not THE strangest, but pretty odd).

Subject: RE: Response Doc Not Updating When Open In UI

Karen,

In your code, if you replaced ws.editdocument(true, childdoc) with some sort of debugging where you looped through the items in childdoc and displayed a messagebox, what would you see?

If the message boxes display all the items and values that you expect, then that is mighty strange!!

Mike

Subject: RE: Response Doc Not Updating When Open In UI

I gave it a try. It displayed the values that I see in the document - the incorrect, old values. However, if I close it without saving and open the one from the view instead, it contains the correct values. Where is it getting that old data from?

Thanks much for the help! I’ll keep plugging away at it. Any further ideas are welcome!

Subject: RE: Response Doc Not Updating When Open In UI

What about Call ws.ViewRebuild? Or delete your cache.ndk and try it then. Are you using a replica by any chance?

Subject: RE: Response Doc Not Updating When Open In UI

I deleted the cache - no luck. I also tried the ws.ViewRebuild - no luck. I really expected the latter to work since doing a Shift-F9 will make it work. Hmmmm.

Subject: RE: Response Doc Not Updating When Open In UI

In case anyone is still following this thread, I contacted Lotus Support and they have confirmed a bug. Their suggestion was to remove the button from the view to force the users to create the responses from within the parent, rather than from the view.

Subject: RE: Response Doc Not Updating When Open In UI

Thank you for the update, Karen!

Subject: Response Doc Not Updating When Open In UI

Would it work if you got a handle on the view and refreshed that view before Set coll = db.UnprocessedDocuments?

Subject: RE: Response Doc Not Updating When Open In UI

I gave it a try. No difference. Thanks though. I’ll keep trying!