Add a Filter and a Prompt Sample

In this sample, the first query contains a filter that allows the report to return a subset of data based on a prompt selection made by the user. The second query contains the data item that provides values for the prompt. This sample requires a second query to ensure that the prompt has the correct Product type values. If you used the Product type data item from the first query to populate the prompt, you could get duplicate values and other errors.

If there are very few conditions, and you can easily manage them in one expression, add more conditions to the contents of the filterExpression element, and then separate them using an and operator. If there are many conditions that you want to manage separately, or if you use prompts to obtain filter values and you want some filters to be required, and others optional, add a detailFilter element to the detailFilters parent element for each additional filter condition.

The prompt is the drop-down list of values, the parameter is a placeholder for the selected product type, and the parameter value is the specific product type that the user selects.

The prompt is represented by the selectValue element in the layout section, and the parameter is located in the filterExpression element. The parameter name for Product type is ?Parameter1?. The Product type values appear at run time. The parameter value is the value that the user specifies at run time when presented with the drop-down list.

The name you assign to the parameter in the layout section must match the parameter specified in the filterExpression element of the filter element.

In this sample, the prompt is defined under the promptPages element. When the report is run, the prompt is shown separately from the report results. The prompt page usually includes a prompt and prompt buttons. You can also put the prompt control directly on the report page.

The prompt page must contain a way to proceed to the next step of the prompt report. In this sample, buttons are provided for this purpose. When the user clicks Finish, the next step is for the report to run because this sample includes only one parameter and one prompt page. If you build reports that include multiple parameters or multiple prompt pages, the next step prompts the user to supply values for other parameters. If you do not want to use prompt buttons, you must set the autoSubmit attribute on the selectValue element to true.

The XML that shows the filter and the elements required to produce the prompt is highlighted in bold:

<report xmlns="http://developer.cognos.com/schemas/report/7.0/" 
	expressionLocale="en-us">
 <modelPath>/content/package[@name='GO Sales and Retailers']
	 /model[@name='model']</modelPath>
 <queries>
  <query name="Query1">
   <source>
    <model/>
   </source>
   <selection>
    ...
   </selection><detailFilters>
<detailFilter>
<filterExpression>[gosales_goretailers].[Products].[Product
type] = ?Parameter1?</filterExpression>
</detailFilter>
</detailFilters> 
  </query>
  <query name="Query2"> 
   <source>
    <model/>
   </source>
   <selection>
    <dataItem aggregate="none" name="Product type">
<expression>[gosales_goretailers].[Products].[Product type]</expression>
</dataItem> 
   </selection>
  </query>
 </queries>
 <layouts>
  <layout>
   <reportPages>
    <page name="Page1">
     ...
    </page>
   </reportPages>
   <promptPages> 
    <page name="Prompt Page1">
     <pageBody>
      <contents>
       <selectValue multiSelect="false" parameter="Parameter1" refQuery="Query2"
required="true" selectValueUI="dropdown">
<useItem refDataItem="Product type"/>
</selectValue> 
      </contents>
      <style>
       <defaultStyles>
        <defaultStyle refStyle="py"/>
       </defaultStyles>
      </style>
     </pageBody>
     <pageFooter>
      <contents>
       <promptButton type="cancel"> 
        <contents/>
        <style>
         <defaultStyles>
          <defaultStyle refStyle="bp"/>
         </defaultStyles>
        </style>
       </promptButton>
       <promptButton type="back"> 
        <contents/>
        <style>
         <defaultStyles>
          <defaultStyle refStyle="bp"/>
         </defaultStyles>
        </style>
       </promptButton>
       <promptButton type="next"> 
        <contents/>
        <style>
         <defaultStyles>
          <defaultStyle refStyle="bp"/>
         </defaultStyles>
        </style>
       </promptButton>
       <promptButton type="finish"> 
        <contents/>
        <style>
         <defaultStyles>
          <defaultStyle refStyle="bp"/>
         </defaultStyles>
        </style>
       </promptButton>
      </contents>
      <style>
       <defaultStyles>
        <defaultStyle refStyle="fp"/>
       </defaultStyles>
      </style>
     </pageFooter>
     <style>
      <defaultStyles>
       <defaultStyle refStyle="pp"/>
      </defaultStyles>
     </style>
    </page>
   </promptPages>
  </layout>
 </layouts>
 ...
</report>