Querysave: unexpected behavior
Posted by Theo Heselmans on February 27th, 2009
It doesn't happen to me a lot, but this time, I'm dumbfounded.
I hope it's just me, on a Friday.
Please try the following little experiment (I used Notes 7):
- Create a new form and give it a name
- Put a field on it and call it e.g. 'Company'
- Give this field a default value e.g. "aaaa"
- Create a Querysave and put in the following little script:
Sub Querysave(source As Notesuidocument, Continue As Variant)
Call source.FieldSetText("Company","bbbb")
Print source.Document.Company(0)
source.Document.Dummy=""
End Sub
- Start the debugger
- Preview this form
Move the debugger window a bit, so you can have a look at the field in the background.
Let's step through the Querysave code
- Call source.FieldSetText("Company","bbbb")
This gives the field on the form another content. Everything cool so far. You see the changes on the form. - Print source.Document.Company(0)
The old value "aaaa" is printed.
Hmm, OK, you look at the back-end document, but still weird, as the back-end document in memory should reflect the UI doc. - source.Document.Dummy=""
You just create a new back-end field.
The Company field on the form suddenly returns to its previous content !!!!
It looks like the back-end document (in memory) is re-fetched in the UI ???
(even if you do this with multiple fields, they are all restored) - exit the debugger, you don't want to save
Sure, I could just avoid using front-end fields in a Querysave.
The reason I need this is that my customer wants to do an automatic 'uidoc.SpellCheck' just before saving. If I put the SpellCheck in the Querysave (followed by some back-end updates), and the user fixes some typos, all these fixes are reverted to the situation before saving.
Any Ideas ?
Category: Lotus Notes Domino | Technorati: Lotus, Notes, Domino
Comments (4)
Just throwing out what comes to mind...
Maybe put the spell check stuff in postsave? Added bonus of protecting against spell check crashes (if such things exist).
I'm not sure why it acts like that... but I normally make it a practice to only work with either the front-end or the back-end doc in a script.. not both. Mixing them up sometimes leads to oddness... not often, but enough that I try to avoid it.
Hey Theo:
I changed your code to:
Call source.FieldSetText("Company","bbbb")
Print source.Document.Company(0)
Call source.refresh ' Added this new line
source.Document.Dummy=""
and was able to successfully save the new values.
Regards,
Dan
@Kevin: isn't the doc already saved in Postsave ? If I would do the SpellCheck there, it would mean saving again.
@Dave: I do too, but this was for educational purpose only. Just trying to understand what's happening.
@Dan: Your solution indeed works. Tx. Refresh should only refresh computed values, but it seems to be pushing the front-end to the back-end too. Anyway, my customer will be happy I got a solution, tx to you.