Getting Report Parameter Choices from the Database

This article describes how to prompt a user to select a parameter for a report and have those choices come from the database.

It builds on the previous article Setting Up Parameters With the Design Studio.
This article assumes that you've completed steps 1-5 in the previous article. Please note that the version of Design Studio I am using is version 1.7.0 which is a bit different from the version used in the previous article.

Define the inputs

This section is very similar to the previous article with the major difference being that you only need to create one input instead of two.

  1. Right-click on the folder named Inputs in the Process Inputs box. Select Add... | Input from the menu.
  2. In the new editor page, type CUSTOMER in the textbox labeled "Name".  Leave the Type defaulted to string.
  3. Check the box labeled "Has Default Value". This is very important. Even if you don't want a default value you MUST check the box. Otherwise you will get a NULL pointer exception being thrown when you run the action.
  4. Save your action sequence

 Get the selections from the Database

  1. In the Process Actions box, click the 'Add' button and choose 'Get Data From > Relational'
  2. Rename you action, e.g. Get Customer Selections
  3. Enter your JNDI name, for this example we will use 'SampleData'
  4. Now enter your SQL that will return a result set of the values you want the user to choose from.
    • You can return multiple columns in your result set.
    • One of those columns needs to contain the values that you want to use in the SQL for your report. e.g. the primary key part of the foreign key relationship
    • You can also return a second column that can be used to name those choices to make the choice screen more user friendly.
    • e.g.
      SELECT CUSTOMERNUMBER, CUSTOMERNAME
      FROM CUSTOMERS
      
  5. Now set the result set columns to be the EXACT names of the columns returned in your SQL. Make sure you use 'string' for the column type regardless of what is actually returned (otherwise the column name won't appear in the Prompt action below). For this example it would be
    • CUSTOMERNUMBER:string
    • CUSTOMERNAME:string
  6. Now name the result set e.g. CUSTOMER_SELECTIONS
  7. Save your action secuence

Prompt the User

  1. In the Process Actions box, click the add button and select 'Prompt/Secure Filter'
  2. Rename it if you want
  3. In the Prompt For box click the add button and select the input you want the user to select, in our case CUSTOMER
  4. Type in a prompt message
  5. Select a prompt style, seeing as we only want the user to select one choice go with 'Pulldown'
  6. In the source of choices select the result set returned from the previous action i.e. CUSTOMER_SELECTIONS
  7. Now you choose which columns will be used for the value of the selection and which one for the name. For this example choose CUSTOMERNUMBER for the value and CUSTOMERNAME for the name. This way the CUSTOMER input will be given the NUMBER of the customer chosen but the user will actually select the NAME of the customer.

Use the Parameter in you SQL

  1.  In the Process Actions box, click the 'Add' button and choose 'Get Data From > Relational'
  2. Rename you action, e.g. Get Customer Selections
  3. Enter your JNDI name, for this example we will use 'SampleData'
  4. Now enter your SQL that will return a result set for the report
  5. You can use any inputs by wrapping it in {} and prepending the word PREPARE: to the name. e.g.
    SELECT *
    FROM ORDERS
    WHERE CUSTOMERNUMBER = {PREPARE:CUSTOMER}
    

Selecting multiple Choices

To allow the user to choose multiple options you only need to change the above steps in a few places.

  1. When creating you input, select string-list instead of  string for the type
  2. In the Prompt Style selection choose one of the styles that allow for multiple selections, e.g. Check List
  3. In your report SQL use the IN operator instead of = e.g.
    SELECT *
    FROM ORDERS
    WHERE CUSTOMERNUMBER in ({PREPARE:CUSTOMER})
    

Sample Action Sequences

Tutorial.xaction 

Tutorial-MultiSelection.xaction