Working with fields
You can access the properties of any form field in a form. The field information is read only and can be used to configure entry fields and input validation formulas in windows that represent forms in a Smalltalk application.
Smalltalk classes
There are 10 subclasses of AbtLnFormField which model the behavior of all possible fields in a form. There are methods to ask for most of the fields functional properties. Most important are the field formulas common to all classes. Depending on some field property (field is editable or computed) you will find one or more of the following formula types associated with each field: Value Formula (computed fields), Default Value Formula (editable fields), Input Translation Formula (editable fields), Input Validation Formula (editable fields). You can execute those formulas on demand. See chapter 2.6.6. for information about formula handling.
Keyword fields (AbtLnFormFieldKeywords)
Additional methods are available for keyword fields. You can find out about the keyword list and its visual representation on the corresponding Domino form. The protocol includes methods like: isInterfaceCheckBox, isFrame3D and of course keywords. Here is a piece of sample code how to access the field information for a keyword field. Use the sample database called vaforms.nsf provided with Domino Connection.
| localConnection sampleDatabase sampleForm sampleKeywordField |
"Initialize runtime system"
AbtLnEnvironment startUp.
"Create a local connection"
localConnection := AbtLnConnection local.
"Open the test database"
sampleDatabase := localConnection openDatabase:'VASAMPLE\VAFORMS.NSF'.
"Get the sampleDatabases form named 'FormulaTest'"
sampleForm := sampleDatabase formNoteByName: 'FormulaTest'.
"Get the first (and only) keyword field of the sample form"
sampleKeywordField := sampleForm allFormFields detect:
[ :field | field isKeywordField ].
"Write keywords of the field to the transcript"
Transcript cr; nextPutAll: 'Keywords : '; cr.
sampleKeywordField keywords do: [ :keyword |
Transcript nextPutAll: keyword; cr ].
"These keywords are computed by a formula. Read the formula"
Transcript nextPutAll: 'Choices formula : '.
sampleKeywordField usesFormulaForChoices
ifTrue: [ Transcript nextPutAll:
sampleKeywordField choicesFormula text ; cr ].
"Read the user interface settings"
Transcript nextPutAll: 'User interface : '.
Transcript nextPutAll: sampleKeywordField interface; cr.
"Close database and runtime environment"
sampleDatabase close.
AbtLnEnvironment shutDown.
Number fields (AbtLnFormFieldNumbers)
Number fields can be queried for the number format which was set up during form design. You can find out about decimal places, parentheses on negative numbers etc.
Time and date fields (AbtLnFormFieldTime)
Time and Date fields offer a variety of additional methods to learn about the time and date format that was specified in the form field. You can find out if the field was configured to display the time or the date component of the underlying AbtLnItemTimeDate. You can also retrieve the time zone settings and the time display formats.
Names fields, Authors, Readers
In Names fields, you can access the information which of the following data sources is allowed to specify the names list: ACL, Address Dialog or View Dialog.
Associating forms and documents
When using the Notes client, the difference between a form and a document is not always obvious. Working with Domino Connection the distinction becomes very clear.
If you do not want to emulate the behavior of a form regarding its program logic (which is contained in the field formulas), you can easily use the newNoteFromForm: method in the class AbtLnDatabase to create a document containing the basic field names and type information defined in a certain form note. If you use this protocol you will get an empty AbtLnNote that is preinitialized with a set of AbtLnItems according to the field definitions in the form (see example in the next section). All the fields within the new document will be uninitialized and must be filled by your program. Storing such a document does not invoke input translation or input validation formulas.
If you want to execute all formulas contained in a form's definition, you must use the newNoteFromComputedForm: method. This method executes the default value formulas for each field definition contained in the form you specified and consequently initializes the new documents fields with their default values. Using this method, you associate the given form with the new document. You can subsequently use the other formulas to translate and validate the document's fields. Use the translate and store methods of the class AbtLnNote to perform the corresponding operations.
Note:
The store method invokes the input validation formulas of a form only when a document was created via newNoteFromComputedForm:. If there is no form associated to a document, no formula will be executed automatically.
Using newNoteFromComputedForm: might be time consuming depending on the number and quality of formulas to be executed. Be aware that some formulas (for example @DBLookUp()) might need a long time for evaluation. Make sure that you really need to use the default value formulas in your application or consider using newNoteFromForm: and perform some of the necessary initializations using Smalltalk.
Here is a sample which demonstrates the two possibilities of creating documents using form information:
Before you look at the Smalltalk code, understand how the used form is set up. What follows is a subset of the information generated by the Domino design synopsis function for the form named: 'FormulaTest' :
Form Information:
Form: FormulaTest
Field: NoFormula
Datatype: Text
Field Type: Editable
Field: DefaultFormulaField
Datatype: Text
Default Value Formula: "This is a default value"
Field: TranslationFormulaField
Datatype: Text
Default Value Formula: "lower case default value"
Input Translation Formula: @UpperCase(TranslationFormulaField)
+ " NOW TRANSLATED TO UPPERCASE";
Field: ValidationFormulaField
Datatype: Text
Default Value Formula: "Short default value text"
Input Validation Formula: @If((@Length(ValidationFormulaField)
<30);@Failure("Input string is
too short in ValidationFormulaField -
must be 30 characters or longer");
@Success);
Field: KeywordField
Datatype: Keywords
Field Type: Editable
Keyword User Interface: Standard
Allow Values Not In List: No
Allowable Keywords Formula: @Explode(@Text(@Today) + "
" + @Text(@Yesterday));
Here is Smalltalk code that operates on the form:
| connection database formNote noteWithForm simpleNote errorReporter |
"Start runtime system"
AbtLnEnvironment startUp.
"Create a connection to local databases"
connection := AbtLnConnection local.
"Open one of the sample databases provided with the feature"
database := connection openDatabase: 'VASAMPLE\VAFORMS'.
"Display the results of the 'newNoteFromForm:' method on the
Transcript window"
Transcript nextPutAll: 'New document - no forms formula executed'; cr.
Transcript nextPutAll:
(simpleNote := database newNoteFromForm: 'FormulaTest')
printString; cr; cr.
"Display the results of the 'newNoteFromComputedForm:' method on the
Transcript window"
Transcript nextPutAll: 'New document - default value formulas executed';cr.
Transcript nextPutAll:
(noteWithForm := database newNoteFromComputedForm:
'FormulaTest') printString; cr.
"Display the results of the 'translate:' method on the Transcript
window"
Transcript nextPutAll: 'Translation Formula executed for the
initialized document ';cr.
"provoke an exception due to length underflow on field
VALIDATIONFORMULAFIELD"
[ noteWithForm store ] when: AbtLnErrorReporter errorSignal do: :e |
System message: e argument, 'Note can not be stored'.
e exitWith: nil ].
"Put a value to the field that is long enough to pass the input
validation formula"
noteWithForm at: 'VALIDATIONFORMULAFIELD' put: 'This is a very long
String that definitely can be stored in the document'.
"Store the note"
noteWithForm store.
Transcript nextPutAll: 'Validation Formula executed successfully -
document stored ';cr.
"Close the database"
database close.
"Shutdown runtime system"
AbtLnEnvironment shutDown.
When you look at your Transcript window, you will notice the difference between the two documents created: the first document is empty, the second document contains some fields that were initialized by the default value formula.
Note:
There is a field named FORM which is initialized in the new document. This is done by Domino Connection and is not the result of a default value formula.
After the execution of the default value formula, the document that was associated with a form is used to demonstrate the effects of input translation formulas. When you send the translate message, all defined input translation formulas (if any) will be executed. Remember that the formulas will be executed in an order defined by the forms layout (from top left to bottom right).
The document will not be stored automatically, you will have to send the store message to the AbtLnNote. As you see in the sample, the document raises an exception when at least one of the input validation formulas can not be passed. The sample code catches the exception and displays a message box. After setting the contents of the VALIDATIONFORMULAFIELD to a String that is long enough (see input validation formula), the document can be stored.
Last modified date: 01/29/2015