dominoGuru.com
Your Development & Design Resource
Don't save the NotesUIDocument - Form vs. XPage
04/12/2010 12:19 PM by Chris Toohey
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?!