Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looping through a multiple value parameter array

I have a parameter that allows multiple values. Its for a name field in my database. What I want to be able to do is allow the user to put in a name and then have crystal find any name like any of the names they entered. So for example you could put in 4 last names and crystal would return anyone who had any of those names in the name field. I can get the "like" to work just fine, but only when there is one string in the array. Here is my select formula:

    numbervar counter := 1;
    numbervar positionCount:=count({?Customer Name}); //I'm not sure what to put
                                                        here. Count? UBound? 

    if {?Customer Name}[1] <> 'ALL'
    then
    (
         while(counter <= positionCount)
         do
         (       
            {NAMEFIELD} like  '*' & {?Customer Name}[counter] & '*';
            counter := counter + 1;
         );
    ) 
    else
    if {?Customer Name}[1] = 'ALL'
    then
    true
    )

This formula returns all of the names, not the ones in the parameter. Any ideas on what I'm doing wrong?

like image 880
ccarnley7 Avatar asked Apr 10 '12 17:04

ccarnley7


Video Answer


1 Answers

Create a multi-value parameter ({?Customer Name}) with these properties:

  • Default Value: ALL
  • All multiple values: TRUE

Add a row to the parameter's pick-list grid; supply 'ALL' and 'ALL' (without single quotes)

Create a Custom Function (named 'Delimit') with this text:

// Delimit()
// enclose each value in array in **, returning an array
Function (Stringvar Array params)

  Split("*" + Join(params, "*,*") + "*", ",")

Modify the report's record-selection formula:

If {?Customer Name}<>"ALL" Then
    {TABLE.CUSTOMER_NAME} LIKE Delimit({?Customer Name})
Else
    True

Optionally, create a formula to display the parameter's values with this text:

//{@Customer Name}
Join( Delimit({?Customer Name}), ";")
like image 87
craig Avatar answered Oct 23 '22 05:10

craig