Some background first:
A Notes database with 2 forms
(actually it's simplified here, because the db is a lot more complex)

- The main form: a CV
- Response documents for storing Previous Employers

I present them on the web like this (part of the bigger CV form):
Image:Using WebQuerySave with JavaScript
When the user clicks the Add button (or the period-links of existing Employment),
this 'dialogbox' shows up:
(I use a great piece of code to do this popup:
Submodal, by Seth Banks):
Image:Using WebQuerySave with JavaScript
The 'submodal' window is actually an iframe with the following url:
../Employer?Openform&ParentUNIDâ60CE252CB4E4BDC12574B2002B6088
This will effectively create a new (response) form, linked to its parent.

Here the issue:
When the user clicks 'Save & Close', the document needs to be saved, and the 'parent' CV form refreshed, with a new row added (or an existing row updated).
My button executed the following JavaScript code:

var form = document.forms[0];
form.submit();
window.top._doClick('$refresh',this,null,'#Employment');

I spent a lot of time figuring out what was wrong with this code,
as it worked for me most of the time, but almost never for my customer.
The response document was NOT saved all the time !
I called in the help of a friend (tx Peter), and he actually found what the problem was:
The JavaScript does not wait for the submit to finish (there is even no return value),
and does the refresh immediately.
We settled for adding a 2 second pause before doing the refresh.
This helped somewhat, as the 'save' did happen most of the time now,
... but still not every time :-(
It depended to much on the speed of the (inter)network.
Back to the drawing board.

After discussing with another Notes Developer (tx Sven), I found a clean solution:
I let the Save and Close button only perform the submit, NOT the refresh.
Instead I created an agent, executed in the WebQuerySave of the response form,
with the following code:
Print |<SCRIPT language = "Javascript">|
Print |window.top._doClick('$refresh',this,null,'#Employment');|
Print |</SCRIPT>|

I previously only used a URL as the return value of a WQS,
but it looks like the above, using Javascript, worked too.
So now the refresh is only performed AFTER the response document is saved,
and it works all the time :-)
I should have thought of this solution sooner. It would have saved me many (sleepless) hours !

If this solution might be of use to at least one of you, I didn't write this post in vain.
Let me know.

Category:  Lotus  Notes  Domino  | TechnoratiTechnorati: , ,