The Contextual default property enables an attribute in a transaction to have its default value set by context (see Contextual defaults).
The default value is false.
When set to true a few rules and some event code is added to the underlying transaction to achive the required functionality.
Rules may conflict with already existing ones. The developer must analize and solve possible conflicts.
If attribute CountryName has the Contextual default property set to true, the following code is added to the transaction start event:
//+ K2BES.ContextualDefault.Fixed
web
{
&DefaultCountryName.SetEmpty()
If &Mode = K2BTrnMode.Insert
For &TrnContextAtt in &TrnContext.Attributes
If &TrnContextAtt.ValueType = K2BTools.AttributeValueType.Default
Do Case
Case &TrnContextAtt.AttributeName = !"CountryName"
&DefaultCountryName.FromString(&TrnContextAtt.AttributeValue)
EndCase
EndIf
EndFor
EndIf
}
//-
The following rules are also added:
//+ K2BES.ContextualDefault.Fixed
web
{
default(CityName, &DefaultCityName);
}
//-
As you can see, a variable having the default value (&DefaultCityName) is created, its value is initialized in the start event and used in the default rule.
Not all rule conflicts can be solved (or at least we do not know how to solve them). Following is a list of situations where a solution was found.
This problem may arrise when the developer needs to set a default value when no Contextual default is set. Something like a default for a default.
We found a solution for this situation when the default value can be set in the start event. If that is the case, the developer assigns the variable used for the default value in the start event. Usually BEFORE the code added by K2BTools. In this way, if a contextual default value is found, the default set by the developer is overwritten.
We did not find a solution if the default cannot be calculated in the start event. The most common cases is that the default value is (or inferred from) the value of another attribute in the transaction.
|