This one is strange and not sure if this is expected behaviour or a bug.
I am making changes to the back-end of a uidoc while the uidoc is in Read mode. After manipulating the back end, I’d like to refresh the front-end to show the changes. Since uidoc.reload and\or refresh require the document to be in edit mode to use them, I figured I would simply close and reopen the document.
Something like this:
uidoc = ws.currentdocument
doc = uidoc.document
make my changes to doc using LS
Call doc.Save (T, F)
uidoc.Close(True)
Set uidoc = ws.EditDocument(False, doc)
This does not work. When debugging, it seems that once the uidoc.Close(True) event occurs, the value of doc is lost (that is, it becomes nothing, as if never initialized).
Interestingly enough, using uidoc.Close without the immediate parameter (True) works fine.
I have tried moving doc to the Globals section, to no effect.
Anyone ever see this?
Subject: I seem to be losing my LS variables!!!
Use this statement to
uidoc = ws.currentdocument
TO REPLACE THIS
Set uidoc = ws.EditDocument(False, doc)
During yr edits focus has not moved, I presume so using the currentdocument should not change.
Subject: I seem to be losing my LS variables!!!
uidoc = ws.currentdocument
doc = uidoc.document
make my changes to doc using LS
Call doc.Save (T, F)
uidoc.Close(True)
Set uidoc = ws.EditDocument(False, doc)
I believe the problem is “doc” is still pointing at the uiDoc you just closed. What you need to do is “get” the document ID from the backend.
So just before the close have something like
docID = uiDoc.Document.UniqueID ’ I don’t recall if UniqueID is a property of uiDOC
uidoc.Close(True)
Set luView = thisDB.GetView(“View by DOCID”)
if luView is Nothing Then Exit Sub
Set doc = luView.GetFirstDocByKey( docID, True) ’ Again check to make sure such a method
Set uidoc = ws.EditDocument(False, doc)
Subject: RE: I seem to be losing my LS variables!!!
Good idea - does not work though. I suspect this is a real honest to goodnes BUG.
Subject: RE: I seem to be losing my LS variables!!!
I was going to say that it sounds like the dependent NotesDocument object is being deleted when the UIdoc is deleted. This does happen, for instance, when you created a NotesDocument from a NotesDatabase object and you delete the NotesDatabase. But what you’re doing is similar to the Update rich text tip, which is known to work.
If nothing else will work for you, you could save the note ID in a text variable and use that to find the NotesDocument object.
Subject: RE: I seem to be losing my LS variables!!!
If we take Designer help literally, deleting an object also deletes any contained objects. Since doc (as NotesDocument) is contained by uidoc (as NotesUiDocument) here, this should apply, if uidoc was destroyed (maybe you can confirm or contradict the meaning of containment in this context).
However, at least when I try to run the code provided, uidoc does not get deleted when calling the close method … wondering what makes the difference here.
Subject: RE: I seem to be losing my LS variables!!!
I thought you might be on to something, so I did some testing. Instead of initializing doc from uidoc, I got it from getdocument by unid. In other words:
set uidoc = ws.currentdocument
strDocID = uidoc.FieldGetText(“DocID”) ’ which is in a field
Set doc = db.GetDocumentByUNID(strDocID)
So now, deleting uidoc should not be the issue, right? Unfortunately, same result. I suspect I need to report this one to IBM.
Subject: RE: I seem to be losing my LS variables!!!
What happens if you don’t debug, but instead put in an On Error trap (to display the line number and error text) and just run the code? Is there an error, and if so on what line?
Subject: RE: I seem to be losing my LS variables!!!
“Error 4419: Incorrect argument type: object expected”
This is on the following line:
Set uidoc = ws.EditDocument(False, doc)
This seems to confirm that doc is somehow getting “unintialized.” The debug does confirm this. Two lines prior, I can use debug to inspect this object and all of its properties and items. Once I call the uidoc.Close(True) method however, the doc object completely “uninitializes,” and the debug window lists no properties or methods. It is blank.
Subject: RESOLVED FOR NOW: I seem to be losing my LS variables!!!
Okay - it seems as this one is resolved, although the mystery still exists in my opinion. I want to say that I discovered that the problem did not occur on documents that had been closed and then reopened manually. Once this was done, all worked well. Strange to me, and if anyone thinks that this adds to the understand, there you have it.
In any case, I decided to just reinitialize the object AFTER the uidoc close, as follows:
doc = uidoc.document
make my changes to doc
call doc.save(T, F)
uidoc.close(T)
Set doc = db.GetDocumentByUNID(strDocID)
Set uidoc = ws.EditDocument(False, doc)
This works.
I realize that this was suggested by some of the posters, and I did implement this at the top of my code. Theoretically, to me at least, this should work, but it does not. The object is cleared upon closing uidoc, even though the object was NOT initialized via uidoc. BUT, reinitializing it afterwards as I did here DOES work (and should work). So this is really a workaround I guess.
Bizarre…