Official Content

This document is intended to compile methods and properties related to Enumerated Domains.

Samples below use the following Enumerated Domain definition:

Enumerated Domain Name: MaritalStatus
Data type             : C(1)
Values                : Name        Description   Value
                        Single      Single        S
                        Married     Married       M
                        Widow       Widow         W
                        Divorced    Divorced      D

Enumerated Domain methods

Convert()

Use this method when a value that is not known to belong to the enumerated domain needs to be assigned to a field (attribute, variable, SDT member) that is based on an enumerated domain. This happens, for example, when you read a value from an XML or CSV file and want to assign it to an enumerated domain field. The value is a string but GX does not know that its value belongs to the enumerated domain. The Convert() method avoids the type mismatch error that would otherwise occur in this case.

The Convert() method does not check that its parameter's value belongs to the enumerated domain at run-time.

Syntax

<convert>::=<EnumeratedDomain>.Convert'('<expression>')'

View Syntax conventions

Where:

EnumeratedDomain
    Is the name of an already defined Enumerated Domain.

expression
    Is any valid expression. Its data type must match the basic Enumerated Domain data type.

Sample

// The following code raises a "type mismatch" error
&MaritalStatus = "M"
// You should use the following instead:
&MaritalStatus = MaritalStatus.Convert( "M")

Availability: This method is available since version 9.0.

Elements()

Returns a collection populated with all values defined in the Enumerated Domain. Elements in the returned collection are returned sorted by Value. It can be used anywhere a collection can.

Syntax

<Elements>::=<EnumeratedDomain>.Elements'(' ')'

Where:

EnumeratedDomain
  Is the name of an already defined Enumerated Domain.

Sample

// To insert domain values to a table.
For &x in MaritalStatus.Elements()
   new
      MaritalStatusId = &x
      MaritalStatusDescription = &x.EnumerationDescription()
   endnew
EndFor
 
// In a Where clause
For each
   where MaritalStatusId in MaritalStatus.Elements()
   ...
Endfor

Availability: This method is available since version GeneXus X Evolution 1.


Methods of Enumerated Domain based attributes and variables

EnumerationDescription()

The EnumerationDescription() method returns the descriptive text associated to the given enumerated domain value.

Syntax

<EnumerationDescription>::= <Field>.EnumerationDescription'('  ')'

Where:

Field
    Is an attribute, variable or SDT member based on an Enumerated Domain.

Sample

&MaritalStatus            = MaritalStatus.Married
&MaritalStatusDescription = &MaritalStatus.EnumerationDescription()
// &MaritalStatus must now have the value "M" and &MaritalStatusDescription "Married"

&MaritalStatus            = MaritalStatus.Divorced
&MaritalStatusDescription = &MaritalStatus.EnumerationDescription()
// &MaritalStatus must now have the value "D" and &MaritalStatusDescription "Divorced"

Availability: This method is available since GeneXus X.

           


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