Using stored queries to query information

A stored query is a query that is persistently stored in the database.

Why and when to perform this task

A stored query represents a set of items that have the same characteristics. Although stored query definitions are stored persistently, items contained in the stored query are assembled dynamically when they are queried. All stored queries are publicly accessible. You can have stored queries for business process objects, task objects, or a combination of these two object types.

Steps for this task

  1. List the available stored queries. For example, the following code snippet shows how to get a list of stored queries for task objects:
    String[] storedquery = task.getStoredQueryNames();
  2. Check the query defined by a specific stored query.
    StoredQueryData storedquery = task.getStoredQuery("CustomerOrdersStartingWithA");
    String selectClause = storedquery.getSelectClause();
    String whereClause = storedquery.getWhereClause();
    String orderByClause = storedquery.getOrderByClause();
    Integer threshold = storedquery.getThreshold();
  3. Run the query defined by the stored query.
    QueryResultSet result = task.query("CustomerOrdersStartingWithA", 0);
    This action returns the objects that fulfill the query criteria. In this case, all of the customer orders that begin with A.

Related concepts
Queries on business-process and task-related objects