IBM BPM, V8.0.1, All platforms > Programming IBM BPM > Developing client applications for BPEL processes and tasks > Queries on BPEL process and task data > Business Process Choreographer EJB query API > Syntax of the API query method

Filtering data using variables in queries

A query result returns the objects that match the query criteria. You might want to filter these results on the values of variables.

You can define variables used by a process at run time in its process model. For these variables, you declare which parts can be queried.

For example, John Smith, calls his insurance company's service number to find out the progress of his insurance claim for his damaged car. The claims administrator uses the customer ID to the find the claim.


Procedure

  1. Optional: List the properties of the variables in a process that can be queried.

    Use the process template ID to identify the process. You can skip this step if you know which variables can be queried.

    List variableProperties = process.getQueryProperties(ptid);
    for (int i = 0; i < variableProperties.size(); i++)
    {
       QueryProperty queryData = (QueryProperty)variableProperties.get(i);
       String variableName = queryData.getVariableName(); 
       String name         = queryData.getName();
       int mappedType      = queryData.getMappedType(); 
       ...} 
                 
  2. List the process instances with variables that match the filter criteria.

    For this process, the customer ID is modeled as part of the variable customerClaim that can be queried.

    You can therefore use the customer's ID to find the claim.

    QueryResultSet result = process.query
        ("PROCESS_INSTANCE.NAME, QUERY_PROPERTY.STRING_VALUE", 		   "QUERY_PROPERTY.VARIABLE_NAME = 'customerClaim' AND " + 
    		   "QUERY_PROPERTY.NAME = 'customerID' AND " +
    		   "QUERY_PROPERTY.STRING_VALUE like 'Smith%'",       (String)null, (Integer)null, 
          (Integer)null, (TimeZone)null );
    This action returns a query result set that contains the process instance names and the values of the customer IDs for customers whose IDs start with Smith.

Syntax of the API query method


Related reference:
QUERY_PROPERTY view