The cx:fetch element creates a variable of the list type with objects from the database: 

<cx:fetch list="employees" entity="CREmployee">

 ...

</cx:fetch>

In previous example a variabele employees of type list is being created.This list contains all candidate objects available in the database. 

For a description of valild variable names see variables.

Attributes

The following table contains all available attributes for the cx:fetch element. Obligatory attributes are printed bold.

entity

The following values are available for the entity attribute:

qualifier

The qualifier attrubte defines the condition(s) which every object must fullfil before being added to the list. This way available objects are filtered:

<cx:fetch list="employees" entity="CREmployee" qualifier="toStatusNode.value = 'Active'">

ordering

By using the order attribute the objects in the list are sorted. It is possible to order the list items by using several characteristics, like ordering on last names first and within that order on first name. A order vlue looks like:

({key=<object-attribuut>[;sel=<Ascending | Descending>]},..

Note :
T
he hooks <> including the enclosed texts are so called placeholders; replace the hooks and texts with the appropiate values . Enclosed by brackets are optional values. You can use them, but they are not obligatory. 

The following shows how to use the order attribute and demonstrates the use of various attributes working together

<cx:fetch list="employees" entity="CREmployee" condition="toStatusNode.value = 'Active'" ordering="({key=lastName;sel=Ascending},{key=firstName;sel=Ascending})">

 <cx:foreach item="e" list="$employees">

   <cx:write value="$e.informalName"/>

 </cx:foreach>

</cx:fetch> 

In previous example a variable employees of type list is created en filled with candidate objects that have the "Active" status.The candidate objects are subsequently ordered by last name and first name.Finally all candidate names are written.

 

lazy

Use lazy to prevent that all elements are immediately retrieved from the database. Especially useful when only the number of elements in the list is necessary. Or when you expect to only need the first n elements from the list.

 

Example 1
Only display the number of elements without actually retrieving the elements from the database :

<cx:fetch list="employees" entity="CREmployee" lazy="1">

   The number of objects is: <cx:write value="$employees.count"/>

</cx:fetch>

In previous example the variable $employees is like a proxy object. Only until an individual element or its properties is used, like the property "count", will the necessary data be retrieved from the database.

Example 2
At most $N elements are being retrieved from the database:

<cx:fetch list="employees" entity="CREmployee" lazy="1">

 <cx:foreach list="$employees" count="$N">

   Name: <cx:write value="$item.informalName"/>

 </cx:foreach>

</cx:fetch> 

Example 3
Retrieve elements until a condition is met:

<cx:fetch list="employees" entity="CREmployee" lazy="1">

 <cx:foreach list="$employees">

   <cx:if condition="$item.toProductType1Node = nil"><cx:break /></cx:if>

   Name: <cx:write value="$item.informalName"/>

 </cx:foreach>

</cx:fetch>
Did this answer your question?