Accessing data from virtual properties, arrays, or keys

A row query provides access to specific properties of primary and secondary entities that are backed by columns in the database.

A row query cannot directly access virtual properties. The values of virtual properties are provided by methods rather than directly from the database.

A row query can access secondary entities from foreign keys or edge foreign keys. A row query cannot directly access arbitrary properties of secondary entities from edge foreign keys or foreign keys. A row query can provide only the identifier value that these properties contain or specified properties of the secondary entity.

A row query cannot access array properties or one-to-one properties. A row query cannot directly access any properties of secondary entities from array properties or one-to-one properties.

The most straightforward way to access these types of values is to use an entity query instead of a row query.

Alternatively, you can use a bundle. This approach performs a query on the database for each row in the result set to retrieve the necessary entities. The following code demonstrates the use of a bundle and keys to access a virtual property and entities in an array.

uses gw.api.database.Query
uses gw.api.database.QuerySelectColumns
uses gw.api.path.Paths
uses gw.pl.persistence.core.Key

// Get the current bundle from the programming context. 
var bundle = gw.transaction.Transaction.getCurrent()
var query = Query.make(Address)

var results = query.select({
  QuerySelectColumns.pathWithAlias("CUser", Paths.make(Address#CreateUser)),
  QuerySelectColumns.path(Paths.make(Address#PublicID))
})

for (row in results) {
  if (row.getColumn("CUser") != null) {
    var user = bundle.loadBean(row.getColumn("CUser") as Key)
    print("User login name: " + (user as User).Credential.UserName + " created address: " 
            + row.getColumn("Address.PublicID"))
  }
}

To run the preceding code in the Gosu Scratchpad, use the method Transaction.runWithNewBundle instead of Transaction.getCurrent. Enclose the remaining code in a code block, as shown in the following code.

gw.transaction.Transaction.runWithNewBundle( \ bundle -> {
  var query = Query.make(Address)
...
}, "su")

On your production system, Guidewire strongly recommends that you do not use the Guidewire sys user (System User), or any other default user, to create a new bundle.

See also