When validating Lotus Notes forms in a Web application, loss of user-submitted field data can occur on the Domino server.
A simpler solution is available through the use of conventional coding.
Normal practice for validation on a Lotus Domino server is to call an agent on the WebQuerySave event of the form. This agent does all of the validations and redirects users to an error page or prints alerts and returns to a blank form.
- Add one computed for display field -- e.g., "ErrMsg" (you can call it anything you want). Use the same formula you used for the Field Name.
- Add a hidden button (style='display:none") and call the agent on this button. I like to call this button "btnValidate." Use the formula: "@Command([ToolsRunMacro];"agentName") for calling the agent. Remove your agent call from WebQuerySave.
- Modify the agent and after you set up the document:
- Make sure the first statement you make is to set "SaveOptions" to 0 and "ErrMsg" to "" (blank).
- Remove any "print" statements.
- Make sure the messages to be displayed to the user are now set in the field "ErrMsg" (using document handle).
- Remove any redirection in case of error.
- If no error occurs, then simply set "SaveOptions" to 1.
- On "btnValidate," where we call the agent, add the formula below. This will ensure that the form is submitted if the validations are passed and we set "SaveOptions" to 1 in our agent.
"@if(SaveOptions="1"; @Command([FileSave]); @Return(""));
Our agent will be called on the Save button. Since the form is not submitted yet, this is where we will have the document context live.
We don't have any print statements, so it won't overwrite the document context. If validations have failed, we have messages set in our "ErrMsg" field.
After the agent finishes page refreshes and causes alerts to fire from the "Onload" event and all user entered data is there, there is no loss at all. If no error shows, then the next formula agent call, which checks for the "SaveOptions" value, will save the form that submits the form for saving.
Do you have comments on this tip? Let us know.
This tip was submitted to the SearchDomino.com tip library by member Sameer Thakur. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.