For some mis-guided reason, I had thought that you needed to have an underlying Notes Form with which you would bind each input element on the Xpage to so that the database would know how to create a document. While its true that you can do that - in fact its a way of Xpage enabling an existing Notes application - you don't actually need to do that. With a smidgin' of Server Side JavaScript (SSJS) it turns out you can create a document from an Xpage without legacy Notes Design resources.
An Xpage Quick Start
In the steps below, Im going to walk through how to create a simple Xpage, with a single input field and allow you to create documents in the underlying NSF. This is similar to the IBM example, only i focus on one component -- creating a document.
Ok, lets get started.
- Create a new blank application on your local machine, call it "Test1.nsf".
- Go to the Xpages list in the Application navigator and create new blank Xpage. Call it "Main".

- Next from the Controls Palette drag and drop an Edit Box control, and a Button control onto your Xpage.
- Place the cursor in front of the Edit box, and type "Keyword"
- Place the cursor on the button, click the "Properties" Tab in the bottom pane, and change the label text, to "Submit".
Your basic, cut down, no-frills Xpage should look like this.
So now that you've got a form that accepts a single input field, how do you "wire" or connect that field to a notes document? In this Xpage example, we will do this by creating a Request Scoped Variable - which means is a variable that exists on the Server Side once the form is posted to the server -- only, its Scope or the time for which it exist programmatically is limited to the life of the request - in this case the form post to the server - hence s Request Scope Variable. To do this:
- Click on the Edit box control on the Xpage, then click the Events tab in the bottom Pane of designer.
- Next select Data under Properties. Select Advanced. From the drop-down list, select Scoped Variable. In the Parameter field, select Request Scope from the list. Finally,enter a variable name, lets call this variable keyword.

Now comes the SSJS magic. And it deceptively simple, especially if you are already familiar with LotusScript as it shares nearly all of the same class names.
Click the "submit" button, then click the Events Tab in the bottom pane of designer.
Make sure that the onclick is selected (it highlighted by default). Then select Script Editor and make sure that the Server tab is selected (it is by default).
Paste the following code into the box.
var doc = database.createDocument();
doc.replaceItemValue("keyword", requestScope.keyword);
doc.save();
requestScope.keyword= null;
You should see a simple web form like the one below. Enter a value in the Keyword field, and click submit.
The Xpage is creating a new document everytime you press submit! Nice. Whats that I hear you say? You want proof it is creating documents? Ok then, lets add a document counter to the page.
- From the Controls Palette, drag across a Computed field control.
- Add the following Javascript under the Properties tab > Value > Javascript:
return "Number of documents in database: " + database.getAllDocuments().getCount().toFixed()
This JavaScript will return the value of all the documents in the database (note the Javascript dot notation, but the LotusScript like Class names).
Again, save a preview your Xpage and watch the document count increment each time you create a new keyword. Head over to the Developer works article where they extend a similar example to this and include, editing, deletion and viewing actions - again, all in JavaScript.
:)




