How to validate Lotus Notes forms on a Domino server without losing entered data

How to validate Lotus Notes forms on a Domino server without losing entered data

When validating Lotus Notes forms in a Web application, loss of user-submitted field data can occur on the Domino server.

The most popular way of avoiding this is to retrieve the values to be validated through hidden form fields, as well as client-side validations using JavaScript. But when there is a lot of data, this can cause generated HTML pages to be very heavy. Additionally, it's almost impossible when several fields need to be validated against different conditions.

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.

Generally, the WebQuerySave event is called using the JavaScript submit command or using the more direct "@command([FileSave])." In order to maintain data entered by a user, we will modify this process a bit:

  1. 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.

  2. 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.

  3. Modify the agent and after

    Requires Free Membership to View

    Register today to access targeted resources from our editorial writers and independent industry experts focused on Lotus Domino, Notes, Workplace and other related technologies.

    By submitting your registration information to SearchDomino.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchDomino.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

  1. 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.

  2. In the "Onload" event of the form, write some JavaScript to check the "ErrMsg" field and to make sure the alert value of the field is not blank. This will give an error message to the Lotus Notes user on form validation failure.

  3. Make that field blank using JavaScript so that it will not alert on every page refresh after that.

  4. 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.
    More on Lotus Notes and Domino development:
    Can I use LotusScript or JavaScript to validate the date field on a Lotus Notes form?

    Validating form fields using LotusScript

    Compact LotusScript code for field validation

    Validating a Lotus Notes formula from LotusScript

    JavaScript Learning Guide

    "@if(SaveOptions="1";
    @Command([FileSave]);
    @Return(""));
  5. Instead of calling "submit" on the form's Save button, call "click" of "btnValidate" using JavaScript.

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.

This was first published in May 2007

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.