Tuesday, March 4, 2014

Layout Input Elements with an Input Grid Element

Often multiple input values are collected from the user and it can be difficult to get the input elements aligned neatly in a two-column format. The Input Grid element, which is a container for input elements, provides a method for achieving such an alignment.

The example below is a report definition that collects the date range criteria for a report, using Input Date elements organized within an Input Grid element, and executes a report based on the criteria.

Figure 6.15: Definition Editor Panel after adding Input Grid and Input Date elements

The Input Date elements’ Caption attributes have been used to provide captions and, when the report is previewed, the inputs look like this:

Figure 6.16: Report Preview Panel   

Adding Report Criteria

While generating static reports is useful, many reports must support the selection of report criteria by the user to narrow the scope of the report.

For this example, we’ll start with the simple Customer List report created in Chapter 2, and add the capability to limit the customer list by country.

Step 1: Copy the basic report.

First, make a copy of the “Chapter2Report” report, and rename the report “Chapter6Report1”.


Step 2: Add the criteria selection to the report

There are a number of input elements available to collect input from the user. For visual clarity, you may care to collapse the dtCustomers element, hiding all of its child elements.

 In this example, add the following beneath the Body element and move them above the dtCustomer element: a Label element to prompt the user for the criteria, a Space element, an InputText element to accept input from the user, and a New Line element. Give the Label and InputText elements appropriate IDs.

Figure 6.1: Definition Editor Panel after adding input elements

Set the Label element’s Caption attribute to prompt the user for input (i.e. “Enter the Country:”).

Figure 6.2: Attributes Panel after setting Label element attributes

Hint: An alternative to using a Label element to prompt the user for input is to set the InputText element’s Caption attribute.   

Step 3: Add a button to execute the report

Add New Line and Button elements below dtCustomers to execute the report.  


Figure 6.3: Definition Editor Panel after adding Button element 

Set the Button element’s Caption attribute to provide a description of the button action (i.e. “Run Report”).


Figure 6.4: Attributes Panel after setting Button element attributes
Beneath btnRunReport add Action.Report and Target.Report elements to specify the report to run when the button is clicked.

Figure 6.5: Definition Editor Panel after adding Action and Target elements 

In this example, the report executes itself with the desired criteria. Therefore, set the Target element’s Report Definition File attribute to this report (i.e. “Chapter6Report1”).


Figure 6.6: Attributes Panel after setting Target element attributes 
Expand dtCustomers and modify the dlCustomerData data layer element’s Source attribute to use the criteria:

SELECT * FROM Customers
WHERE Country LIKE '@Request.txtCountry~%'

When the button is clicked, the HTML form in the report that contains the text input element will be submitted. Form fields submitted in this manner are “sent” to the target report definition as values identified by @Request tokens, followed by the input element ID. So @Request.txtCountry~ represents the country value entered by the user. The percent symbol (%) in the query is SQL syntax is a “wildcard” that enhances matching and is not part of the token.

Now, preview the report. Because the report expects an @Request token, you’ll be prompted to enter one. This is a handy Studio feature that lets you feed request variables to reports when testing. For now, however, just click Continue.

Figure 6.7: The Test Parameters Input dialog box 
Your report should appear in the Preview window and will contain all customers. Remember, we haven’t provided any criteria yet to limit the report to specific countries.

Enter some country criteria (the names of most countries or abbreviations, such as USA or UK, for some) and click the button. Your report should be limited to the correct entries. 

To see the effect of that percent sign (%) in the SQL query, enter just the letter “F” in your criteria and click the button. The report will include customers from Finland and France. 


Figure 6.8: Report Preview Panel after criteria “UK” entered

Step 5: Remembering the selection criteria

Notice, however, that our criteria textbox is cleared each time the report runs so we’re not really sure what criteria we’re viewing. To allow the report to “remember” the value entered by the user, set the Input Text (txtCountry) element’s Default Value attribute to the value “@Request.txtCountry~”.


Figure 6.9: Attributes Panel after setting Input Text element attribute 

The value entered will now appear in the Input Text element each time the report runs.

Step 6: Using a drop-down list

Instead of requiring the user to type in the country, a more user-friendly approach is to allow the user to select the country from a list of valid values. Remark the Input Text  (txtCountry) element, and add just below it an Input Select List element. 

Figure 6.10: Definition Editor Panel after adding the Input Select List element

To supply valid values for the Input Select List, add a DataLayer.SQL element beneath it and give it an appropriate ID.


Figure 6.11: Definition Editor Panel after adding the DataLayer element

Set the data layer’s Connection ID attribute to “connNorthwind” and, to retrieve a list of unique country names from the database, use the DISTINCT keyword in the SQL query in the Source attribute. The attributes should be as shown below:

Figure 6.12: Attributes Panel after setting the DataLayer element attributes
Set the Input Select List element’s Caption Column and Value Column attributes to the name of the appropriate column in the Data Layer (i.e. “Country”). In this example, these attributes are both set to the same column. But often the Caption Column is set to a user-friendly value and the Value Column is set to a key. 

In addition, set the Input Select List element’s Default Value attribute to the request token that will contain the value selected by the user. 

Figure 6.13: Attributes Panel after setting the InputSelectList element attributes 

Hint: The Input Select List element’s Include Blank attribute is used to add an empty item to the list and the Include Blank Caption attribute is used to specify an item to add to the list (i.e. “All” or “None”). When the user selects the “blank” item, the @Request token returns an empty string.   

Finally, modify the Data Layer (“dlCustomerData”) element’s Source property to use the country name selected from the list:

SELECT * FROM Customers
WHERE Country = '@Request.selCountry~'

Notice that the percent sign (%) is no longer used in the query.

Now, preview the report and select different countries from the list.

Figure 6.14: Report Preview Panel

To allow the user to select multiple items from the list, set the Input Select List element’s Multiple Selections attribute to “True”. In addition, modify the Data Layer (“dlCustomerData”) element’s Source property to retrieve all the selected items. 

SELECT * FROM Customers
WHERE Country IN (@SingleQuote.Request.selCountry~)

When an input select list allows multiple items to be selected, the @Request token returns a comma-separated list of items. The @SingleQuote token inserts single quotes around each item selected in the input select list. These two tokens used together allow the selected items to be easily used with the SQL statement IN clause. 

Chapter VI. Creating Interactive Reports

The purpose of this chapter is to build more dynamic, flexible reports using the family of input elements provided by Logi Report. In particular, we’ll demonstrate the collection and use of report criteria, the different methods of laying-out input elements, and input validation.