Contextual defaults

Contextual defaults refer to values that new records may have if added in a given context. To clarify, say you are looking for a hotel for 2 people, starting on May 20 and ending May 24. It would be nice if, when you select a hotel, the booking confirmation is set to start on May 20, end on May 24 and for 2 people. You can change any value, but they are set to the value you were searching for.

Another example is prompting. If the application user searchs for a field value (say a Customer name), it does not exist and can add it (a Customer), it's highly probable that if add is selected (add Customer), the searched value be the default for the searched field (Customer name).

K2B Tools easies the process of defining and setting Contextual defaults.

Using contextual defaults

The first step in working with contextual defaults is defining what attributes in what transaction support it. This is done by setting the Contextual default property to true for the given attributes in the given transactions.

Once the attributes that accept contextual default are indentified, the developer can use the Set transaction contextual default property and Set as contextual default for property to enable and identify what values should be set as contextual defaults for what attributes.

An example

A basic application records people and the country they live in. The country transaction looks like the following:


Attribute CountryName has the Contextual default property set to true and the K2BTools Prompt pattern, with the Insert enabled property set on, was applied to the transaction.

The person transaction has the following structure:


When the application user opens the prompt for Country, searchs for a non existing one, if the he/she selects de Add action, the new Country transaction opens and the value of the Country name attribute is the most recently searched Country name.