Following on from https://tickett.wordpress.com/2011/05/19/crystal-reports-training-tutorial-part-2-building-a-basic-report/ I’m going to skim through the use of parameters (I initially thought this would be a really brief part of the tutorial then realised there is actually quite a lot to them!).

Parameter Types
Boolean: True or false (dropdown)

Currency: To the best of my knowledge this behaves the same as the number parameter type (textbox with validation)
Date: Pick from a calendar
DateTime: Pick from a calendar (textbox with validation for time)

Number: Textbox with validation
String: Textbox
Time: Textbox with validation

Parameter Options
I’m not going to cover all of the options- I recommend you experiment with them all to see how they behave for yourself
Prompt Text: Most common of all the options- this allows us to name our parameter something and have a more user friendly prompt

Allow Multiple Values: Goes without saying (see above)
*Note* Parameters which accept multiple values are great for your selection criteria but can be tricky to use for conditional formatting (the parameter now contains an array)
Prompt With Description Only: See below example (set to false)- you can see the values and corresponding descriptions

Now set to true- you can only see the descriptions

Allow Custom Value: See below example (set to true)- you may pick a value from the list or enter your own value

Now set to false- you are forced to pick a value from the list

Allow Range Values: Personally I always avoid the use of range values, and instead I have 2 prompts- one for the bottom of the range and one for the top (FromDate, ToDate for example)
Optional Prompt: Will allow the user to leave the parameter blank
*Note* If using optional parameters you must incorporate the HasValue function every time you access the parameter or the report will fail!
Edit Mask: For string parameter types only

  • “A” (allows an alphanumeric character and requires the entry of a character in the parameter value).
  • “a” (allows an alphanumeric character and does not require the entry of a character in the parameter value).
  • “0” (allows a digit [0 to 9] and requires the entry of a character in the parameter value).
  • “9” (allows a digit or a space, and does not require the entry of a character in the parameter value).
  • “#” (allows a digit, space, or plus/minus sign, and does not require the entry of a character in the parameter value).
  • “L” (allows a letter [A to Z], and requires the entry of a character in the parameter value).
  • “?” (allows a letter, and does not require the entry of a character in the parameter value).
  • “&” (allows any character or space, and requires the entry of a character in the parameter value).
  • “C” (allows any character or space, and does not require the entry of a character in the parameter value).
  • “. , : ; – /” (separator characters). Inserting separator characters into an edit mask is something like hard coding the formatting for the parameter field. When the field is placed on the report, the separator character will appear in the field object frame, like this: LLLL/0000. This example depicts an edit mask that requires four letters followed by four numbers.
  • “<” (causes subsequent characters to be converted to lowercase).
  • “>” (causes subsequent characters to be converted to uppercase).
  • “” (causes the subsequent character to be displayed as a literal). For example, the edit mask “A” would display a parameter value of “A.” If the edit mask is “00A00,” then a valid parameter value would consist of two digits, the letter “A,” and then two additional digits.
  • “Password”. Allows you to set the edit mask to “Password,” you can create conditional formulas specifying that certain sections of the report become visible only when certain user passwords are entered.

Report Layout
We can use the parameters to drive how our report looks (almost all section and field attributes can be determined by the value of parameters)

Create a string parameter called report_title and place it in the report header

Refresh the report, and enter some text for the report title

Let’s try one more example- create a new boolean parameter called hide_detail

Now in the section expert for our page header and detail sections we will enter a conditional suppression formula

Refresh the report choosing detail
And then choosing summary

Selection Criteria
Most commonly report parameters are used to determine our record selection formula
Create a number parameter EmployeeID and modify the record selection expert
{Orders.CustomerID} = {?Customer}
Enter a value

You will see your report displaying only records which meet your criteria

Dynamic
By default parameters are static and provide either:
-a textbox
-a dropdown list of predetermined values (entered while designing the report)
However- you can also create dynamic parameters which pull from a field in the database by selecting dynamic from the list of values box in the top right hand corner for the edit parameter window

Click the value field and select CustomerID
Now modify the record selection formula:
{Orders.CustomerID} = {?Customer}
And refresh the report

If a new value appears in the database they will appear the next time the report parameter is displayed

Cascading parameters can be created where you want to prompt for say Country then State (the selected value from the first parameter will impact the list of available values from the second parameter). I’m not going to cover this.

If you feel I’ve missed anything or have something to add please comment!

L

Advertisements