Recents

 


Default ruleOfficial Content

Assigns a default value to an attribute or variable.

The most common use of this rule is in the Transaction object, in order to initialize an attribute with a certain value (and it can be modified). In this kind of use, the rule is triggered only when the transaction is executed in Insert mode (because when the transaction is executed in other modes like Update, Delete or Display, the attribute already has a stored value, and the objective of this rule isn't to rewrite the stored value).

Also, this rule is offered in other objects with the same objetive: assigning a default value to a variable (but it isn't so usual to define it in other objects, because depending on the object, the variables may be initialized in different sections, like an event, source, etc.).

Syntax#

Default(att | &var, expression);

Where:

att &var
    Is the attribute or variable to be assigned.

expression
    Is any valid expression that can involve a procedure, function, method, constants, variables or other attributes (the result must match the attribute or variable type definition). 

Examples#

1)

Customer
{
  CustomerId*      
  CustomerName         
  CustomerAddress      
  CustomerPhone   
  CustomerAddedDate 
  CustomerState
}  

Customer Rule:

Default(CustomerAddedDate,today());  

Note:#

The behaviour provided by the Default rule proposed in the example, is exactly the same as the behaviour provided by the following rule: 

CustomerAddedDate=today() if insert; 

 

2) The following example shows a rule defined in the Customer transaction, that uses the Previous function, in order to initialize the CustomerState attribute for a new customer which is being inserted (with the value of the previous customer).

Default(CustomerState,Previous());  

 

In other GeneXus objects (like for example, procedures or web panels), the Default rule only can be defined in order to initialize variables, and they will be triggered  at the beginning of program execution. The expression in these cases, only allows: 'literals' between quotes, numbers, and the following functions: Today(), Date() and Sysdate(). Next, an example is shown:

Default(&FirstCustomerId, 1);
Default(&LastCustomerId, 999);

 #

Scope#

Objects  Transaction objectProcedure object, Web Panel object


Was this page helpful?
What Is This?
Your feedback about this content is important. Let us know what you think.