Domino Connection : Working with documents : Smalltalk classes for documents : Creating documents using form information
Creating documents using form information
All prior described methods were operating on preexisting documents. The following section describes how to create a new document using the structure of a form definition.
Creating a "blank" document is very easy. Send the newNote message to an open instance of AbtLnDatabase and you will receive an empty document. Using the addItemNamed: protocols introduced in the last chapter, you can fill in items for your purpose. There is a more convenient way to create documents which are preinitialized according to a form definition. Use the newNoteFromForm: message to create a new document containing all field definitions that are available in the referenced form. When you create a document using newNoteFromForm:, form formulas will be executed: the default value formula on creation of the document, the input translation and input validation formulas on storing the document. An exception is signaled if one of the formulas fails to evaluate properly.
The example below copies a document from the sample discussion database to the sample mail database and adds some fields necessary to show up in the mail database's views.
| localConnection note sampleDatabase sampleMailDatabase newNote |
"Initialize runtime system"
AbtLnEnvironment startUp.
"Build a local connection"
localConnection := AbtLnConnection local.
"Open the sample mail database"
sampleMailDatabase := localConnection openDatabase: 'VASAMPLE\VAMAIL'.
"Open the sample discussion database"
sampleDatabase := localConnection openDatabase: 'VASAMPLE\VASAMPLE'.
"Get the first MainTopic document from the discussion database"
note := (sampleDatabase allNotesFromQuery: 'SELECT Form="MainTopic" ')
first fill.
"Create a new Note using the sample mail databases form
definition for MEMO"
newNote := sampleMailDatabase newNoteFromForm: 'Memo'.
"Add information to MEMO specific fields - copy the
body contents from the discussion document into the
MEMO style document"
newNote at: 'SendTo' put: 'Your Name'.
newNote at: 'Subject' put: 'A copy from the discussion database'.
newNote at: 'Body' put: (note at: 'Body').
"Add new fields to the MEMO note"
newNote addTimeDateNamed: 'PostedDate'.
newNote at: 'PostedDate' put: Time now.
"Add a field that will not be displayed, because there is
no such field definition in the MEMO form."
newNote addCompositeNamed: 'SecretMessage'.
newNote at: 'SecretMessage' put: 'You can only read this using the
Notes client if you use the document property context window'.
"Store the new note"
newNote store.
"Close both databases"
sampleDatabase close.
sampleMailDatabase close.
"Shutdown runtime system"
AbtLnEnvironment shutDown.
With Domino Connection you receive another sample database called abtlncl.nsf. It is a database designed to hold information about Smalltalk methods. There is a very simple form called Method which displays some of the relevant information about a Smalltalk method: the name of the class the method is implemented in, the name of the application the class is defined in, and the actual method selector. You can easily add more fields to this form to expand the database into a "class reference", or even to enhance it in a way that you can share code with other remote users. Here is a piece of code to show you how you can initially fill the database with all method information for the AbtLnBaseApp application.
Note:
This code will take some time to run. It generates a Domino document for each method in the selected application.
 
| db application |
"Start runtime system"
AbtLnEnvironment startUp.
"Open the method notes & comments db"
db := AbtLnConnection local openDatabase: 'VASAMPLE\ABTLNCL.NSF'.
"Collect the information about the AbtLnBaseApp"
application := AbtNotesBaseApp.
application defined do: [ :definedClass |
definedClass methodsDo: :method |
| note |
note := db newNoteFromForm: 'Method'.
note at: 'Selector' put: method printString.
note at: 'Class' put: definedClass printString .
note at: 'Application' put: application printString.
note store.
]
].
"Close the database"
db close.
"Shutdown runtime system"
AbtLnEnvironment shutDown.
Last modified date: 01/29/2015