The conventional way of validating data entered on any Lotus Notes form is to run a WebQuerySave agent. However, if any data is not confirming the expected values, an error message gets thrown to the user.
But the problem of running the WebQuerySave agent is twofold. Either we have to redirect the user to another page -- or take the user to the original form. Unfortunately, either approach causes data entered by the user to be lost forever. The user then has to enter the data again.
To avoid this pitfall, follow these steps:
- In the "Computed for display field," use the name "errMsg." Make sure that the formula has the same field name as itself.
- Use the modified WebQuerySave agent. This Lotus Notes agent will be now modified. Any print statements written inside will be removed. It will set any message in the "errMsg" field and exit. At the conclusion of the agent, it will set "SaveOptions" to "1" or "0" -- depending on the success of the validations.
- Set up the hidden validate button with the following formula:
@Command([ToolsRunMacro];"YourAgentName"); @if(SaveOptions="0"; @Command([FileSave]);@Return(@False));
- Remove the agent call from the WebQuerySave agent.
- Click the "SaveButton" -- or any other button that can invoke a form submission -- instead of submitting the form call click of the validate button. This will run an agent and set your "SaveOptions" accordingly.
If SaveOptions is set to "0," this means validations have been successful and it will save the form -- or else do nothing. In that case we have already set "errMsg" in an agent and after execution of the agent, the Web page gets refreshed and our Onload script will give an alert with the error message we set. This all happens without losing any data.
There is no need to use Ajax or any preloaded data for a client-side comparison. You should do your validations on the server and give alerts to your Lotus Notes users.
Do you have comments on this tip? Let us know.
Related information from SearchDomino.com:
This tip was submitted to the SearchDomino.com tip library by member Sameer Thankur. 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.