Enumerated Domains Methods and Properties

Official Content
This documentation is valid for:

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

EnumeratedDomain.Convert( <expression> )

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. Values in the returned collection are not guaranteed to be in any specific order (neither alphabetic nor the one the domain was defined). It can be used anywhere a collection can.

Syntax

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

 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.





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