dominoGuru.com

Your Development & Design Resource

Don't save the NotesUIDocument - Form vs. XPage

Not saving tastes like chicken! I think the majority of us know how to kill the NotesUIDocument from saving to a NotesDatabase in traditional (or what some are now calling legacy) Lotus Notes Domino Application Development, but I thought I would take a few moments to review the best practices technique as well as talk to the simplistic counterpart approach in XPages.

Legacy Technique: SaveOptions

In a Form Design Element, the addition of a Field named SaveOptions will give you additional control over the Create and Update methods of the NotesUIDocument with it's NotesDocument. Simply put, it will allow you to conditionally save the changes to the given document.

The syntax is simple:

"0" (with quotes) will cancel the NotesUIDocument from submitting it's UI-driven changes to the target NotesDocument.

"1" (with quotes) will force the NotesUIDocument to submit. You can actually put any value in here other than "0" and it will submit as it normally would.

The Field can be editable, which will create a SaveOptions NotesItem in the NotesDocument which I really don't recommend, or Computed for Display (which I do recommend)... if you're using legacy Design Elements and development techniques.

XPages and SSJS

XPages maintain their own NotesUIDocument/NotesDocument relationship via the Data Source, where a Form Element of the given XPage handles Create, Read, Update, and Delete functions of the NotesDocument in a NotesDatabase.

Unlike the legacy Best Practices technique, you do not have to add a SaveOptions Field to your XPages to control the submission. Since the querySaveDocument Event is ServerSide JavaScript-based, all we really need to do is conditionally return False!

A quick example from my upcoming developer2010 presentation demo application:

importPackage(com.dominoguru.mvc);
if (project.isNewNote()) {
    var returnDoc:NotesDocument = jmvc.apiPOST(project.getDocument());
} else {
    var returnDoc:NotesDocument = jmvc.apiPUT(project.getDocument());
}
return false;

Pretty simple huh? Event logic defined in the Event. It just makes sense, doesn't it?!


About the author: Chris Toohey

Thought Leadership, Web & Mobile Application Development, Solutions Integration, Technical Writing & Mentoring

A published developer and webmaster of dominoGuru.com, Chris Toohey specializes in platform application development, solutions integration, and evangelism of platform capabilities and best practices.



More from dominoGuru.com


dominoGuru.com is powered by IBM Notes Domino XPages & hosted by Prominic.NET

Contact Us

Use our Contact / Feedback form or one of these email addresses:

Creative Commons License

Except where otherwise noted, dominoGuru.com by Chris Toohey is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.