Manage Learn to apply best practices and optimize your operations.

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 field data can occur on the Domino server. In this tip, SearchDomino.com member Sameer Thakur explains how to remedy this problem using a modified WebQuerySave method.

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

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

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

  6. 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(""));
  7. 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 last published in May 2007

Dig Deeper on Web Development for Lotus Notes Domino

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchExchange

SearchContentManagement

Close