Assignment Command for variables

Official Content
This documentation is valid for:

Sometimes, we may want to assign a value to a variable or a variable property, within the definition of an object.

The object section where the assignment may be defined depends on the object (events in web panels, source in procedures, etc.)

The value type must match the variable or variable property type. Otherwise, the navigation report will display a warning message.

It is possible to assign a fixed value, a value that results from evaluating an expression or an inline formula, or a value stored in an attribute or variable.

Syntax

&var | &var.property operator expression

Where:
&var | &var.property
    Is the variable or variable property to be assigned. 

operator
    One of the following assignment operators: = , +=, -=, *=, /=.

expression 
    Assignable expressions are: Attributes, Variables, Constants, Functions, Arithmetic Expressions, Inline Formulas.

Examples

Customer
{
   CustomerId*
   CustomerName
   CustomerAddress
   CustomerPhone
}

Invoice
{
   InvoiceId*    (Autonumber property = Yes)
   InvoiceDate
   CustomerId
   CustomerName
   InvoiceAmount
}

This example assigns, to a variable, the aggregate result of all invoice total amounts (this code may be included in a procedure source or web panel event) :

&InvoicesTotalAmount = Sum(InvoiceAmount)

This example assigns the true or false value to a variable, depending on whether a specific customer has invoices or not  (this code may be included in a procedure source or web panel event, upon considering if the context of the web panel has base table or not) :

For each
    where CustomerID=15                        
    defined by InvoiceDate
         &CustomerHasInvoice=True
when none
         &CustomerHasInvoice=False
EndFor

Note: Instead of filtering by a fixed value of CustomerId, the object may receive a variable as a parameter (for example &CustomerId in the parm rule) and use it in the where clause.

Let's now suppose we have configured the Invoice transaction Bussines Component property = True, and the &Invoice variable type = Invoice.
The following code assigns a value to each &Invoice variable property. Following such assignments, it inserts the customer record:

&Invoice type = Invoice

&Invoice.InvoiceDate=&today
&Invoice.CustomerId=10
&Invoice.InvoiceAmount=100
&Invoice.save()
Commit

Scope

Objects Procedure object, Transaction object, Web Panel object
Languages .NET, Java, Ruby, Visual FoxPro
   

See also

Assignment Command for attributes
Assignment rule





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