Assigns a default value to an attribute or variable.
Default(att | &var, expression);
att | &var
Is the attribute or variable to be assigned.
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).
Objects: Transaction, Procedure, Web Panel
This rule is mostly used to initialize an attribute with a certain value, which can be modified, in a Transaction object. Here, the rule is triggered only when the transaction is executed in Insert mode. 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 is not to rewrite it.
Although this rule can be used in other objects with the same objective, its use is unusual because depending on the object, the variables may be initialized in different sections, like an event, source, etc.
The behavior provided by the Default rule proposed in the example, is exactly the same as the behavior provided by the following rule:
CustomerAddedDate=today() if insert;
The following example shows a rule defined in the Customer transaction, that uses the Previous function, to initialize the CustomerState attribute for a new customer which is being inserted (with the value of the previous customer).
In other GeneXus objects (like procedures or web panels), the Default rule can only be defined 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(). An example is shown next: