This document describes how to set default values when creating new records.
There are two types of default values. These types are listed below and described in more detail in separate sections.
- Client default values: Client default values are set in the server and visible in the client. These values might be accepted as is, or modified before being sent to the server together with all other client information.
- Server default values: Server default values are unknown at the client side during registration. These values are set by the server and should be sent back to the client.
Client Default Values
The client defaults give the end-user some default values before starting to register a new object in the client.
These defaults are then used like any other attribute on the screen (and maybe updated) before being sent in the ordinary packed attribute string to the server environment. The default values will be validated in the server like all other attributes, even if the field is not modified by the end-user.
Algorithm for client defaults
- User press new.
- Fetch the entities default values by calling
New__method in PREPARE mode.
- The procedure
New__calls the implementation method
- An overridden version of procedure
Prepare_Insert___adds the default values to the attribute string by calling system services dedicated for this purpose i.e. the
- The client will put the attribute value in the corresponding data field or column.
Prepare_Insert___is mainly for the client but this method can be initiated from the server as well. If the record contains enumeration values, you should remove the client representative of the enumeration value from the attribute string, especially if you change the server value in your business logic.
Server Default Values
Server defaults are values that are set by the server if the value is not set by the client in the attribute string. Typical attributes are columns that are mandatory in the database, but are not mandatory in the client environment. The client/server communication model suggests that all default values set by the server when calling the methods
New__ * *or
Modify__ are added to any attribute string(s) when they are sent back to the client to avoid unnecessary database queries. That is why the parameter
attr_ is of type
IN OUT in all methods for inserting or the updating of records.
The setting of server default values should be placed in the procedure
Insert___ (when creating records), or in
Update___ (when modifying records). These methods can be overridden as shown in the example below. If sequences are used for generating keys, then this code must also be placed in these methods. It is important that the client attribute flags define the client behavior of an attribute, a column that gets the value from a sequence should not be mandatory or not even able to insert, even if the attribute is a key column. The column can still be set to not null using the property Nullable on the attribute in the model, seeDbTableColumnNullable.