Pitfall on NotesUiDocument vs. NotesDocument field changes - unexpected "Reload"
When mixing field changes in a NotesUiDocument and the corresponding NotesDocument, it is very important to make sure that they do not have any side-effects on each other. Could be ugly...
To see what I mean, try this one:
Build a simple form with one text field "myField" and a button. The button has the following code in the Click event:
Now open the form in Notes and fill the field with some content. The button *should* do the following (that is what I would expect):
Well, *this* is what it actually does:
The change in the backend seems to make Notes reload the NotesUiDocument; it is not a real reload, because none of the events is triggered; maybe Notes just forgets the changes in the UI, I don't know (does someone? please comment). Whatever it is, the changes in the UI will be lost. -- Mixing UI field changes and backend changes in Notes: not a good idea...
To see what I mean, try this one:
Build a simple form with one text field "myField" and a button. The button has the following code in the Click event:
' get NotesUiDocument
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set uidoc = ws.CurrentDocument
' first check the current content in the field
Msgbox uidoc.FieldGetText("myField")
' change the field content in the uiDoc and show us, that it was successful
Call uidoc.FieldSetText("myField", "my new content")
Msgbox uidoc.FieldGetText("myField")
' now change a totally different field (item) in the backend document
Call uidoc.Document.ReplaceItemValue("xy", "1")
' oops... what happened to my ui changes?
Msgbox uidoc.FieldGetText("myField")
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set uidoc = ws.CurrentDocument
' first check the current content in the field
Msgbox uidoc.FieldGetText("myField")
' change the field content in the uiDoc and show us, that it was successful
Call uidoc.FieldSetText("myField", "my new content")
Msgbox uidoc.FieldGetText("myField")
' now change a totally different field (item) in the backend document
Call uidoc.Document.ReplaceItemValue("xy", "1")
' oops... what happened to my ui changes?
Msgbox uidoc.FieldGetText("myField")
Now open the form in Notes and fill the field with some content. The button *should* do the following (that is what I would expect):
Display the current field content in an alert
Change the field content in the uiDocument and display the new content
Add a new item "xy" with the value "1" in the backend
Display an alert with the new content of the ui field (same one as in the last alert)
Well, *this* is what it actually does:
Display the current field content in an alert
Change the field content in the uiDocument and display the new content
Add a new item "xy" with the value "1" in the backend
Display an alert with the original content of the ui field (same one as in the last alert)
The change in the backend seems to make Notes reload the NotesUiDocument; it is not a real reload, because none of the events is triggered; maybe Notes just forgets the changes in the UI, I don't know (does someone? please comment). Whatever it is, the changes in the UI will be lost. -- Mixing UI field changes and backend changes in Notes: not a good idea...




Last seen at...
2 Comments:
Marcus,
You are correct. Check the AutoReload property of the NotesUIDocument class. You can set this property to False to prevent backend document changes to interfere with UI document.
Still, it is probably best not to mix backend and frontend changes at all.
Sasa
ah, designer help even sais it. Thanks for the info, Sasa :) learned something today...
Post a Comment
Thank you for your comment. It will be published shortly. Keep having a great day!
<< Home