Comparing a typekey column value with a typekey literal
Often you want to select data based on the values of typekey fields. A typekey field takes its values from a specific typelist. A typelist contains a set of codes and related display values that appear in the drop-down lists of the PolicyCenter application.
Gosu provides typekey
literals with which you specify typelist codes in your programming
code. Gosu creates typekey literals at compile time by prefixing typelist
codes with TC_ and converting
code values to upper case. For example, the following Gosu code specifies
the typekey code for open
in the ActivityStatus typelist.
typekey.ActivityStatus.TC_OPENThe Address entity type has a typekey
field named State that
takes its values from the State
typelist. The following sample code uses the typekey literal for California
to select and print all addresses in California.
uses gw.api.database.Query
// Query the database for addresses.
var query = Query.make(Address)
// Restrict the query to addresses in the state of California.
query.compare(Address#State, Equals, typekey.State.TC_CA)
var result = query.select()
// Iterate and print the result.
for (address in result) {
print(address.AddressLine1 + ", " + address.City + ", " + address.State)
}
Use code completion in Studio to build complete object path expressions for typelist literals. To begin, type typekey., and then work your way through the typelist names to the typekey code that you need.
See also
