Table of contents

 




Official Content

Assigns a default value to an attribute or variable.

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). 

Scope

Objects: TransactionProcedure, Web Panel

Description.

This rule is mostly used to initialize an attribute with a certain value, which can be modified, in a  Transaction objectHere, 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.

Samples

Sample # 1

Customer
{
  CustomerId*      
  CustomerName         
  CustomerAddress      
  CustomerPhone   
  CustomerAddedDate 
  CustomerState
}  

Customer Rule:

Default(CustomerAddedDate,today());  


Note:

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; 


Sample # 2

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).

Default(CustomerState,Previous());

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:

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

 

  

Last update: November 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant