Criteria Object Methods and Attributes

A criteria object provides methods and attributes that allow you to return its DQL query string and its pagination details, and to set values for any parameters used in the query string.

Attribute Description
startPosition (Zero-based) number of the first record to return in a paginated list.

This value defaults to 0 if the index value was not specified when creating the criteria object.

pageSize Number of records to return in each page of a paginated list.

A value of -1 means return all records. This is the default value if the pageSize value was not specified when creating the criteria object.

Method Description
setQueryParameter(paramName,value) Assigns a value to a named parameter that appears in the DQL query string.

paramName is the name of a parameter defined in the DQL query string.

value must be either a simple type or an enumeration.

setQueryParameter(paramName,values) Assigns a list of values to a named parameter that appears in the DQL query string.

paramName is the name of a parameter defined in the DQL query string.

values must be a list of either a simple type or an enumeration.

getQuery() Returns the DQL query string defined for this Criteria object.

For example, in the following screenshot the content assistance shows the methods and attributes available on a criteria object.

Example

This example shows how to use setQueryParameter to set a dateRng parameter on a criteria object. This object is then used in a query to find customers whose orders were dispatched in August 2013.

var startDate = DateTimeUtil.createDate("2013-08-01");
var endDate = DateTimeUtil.createDate("2013-08-31");

var dateRange = DataUtil.createList();
dateRange.add(startDate);
dateRange.add(endDate);

var criteria = cac_com_example_ordermodel_Customer.createCriteria(
			"orders.dispatchNote.dateOfDispatch between :dateRng");
criteria.setQueryParameter("dateRng", dateRange);

var customerList = cac_com_example_ordermodel_Customer.findByCriteria(
			criteria);