Login / Register  search  syndication  about

          George Jensen's Blog

George Jensen on Reporting, Business Intelligence, Crystal Reports, Visual Analyzer, and more.

Using Multiple Value Parameters to Select Records for your Crystal Reports

I have often been asked to provide the ability to allow users a multi select parameter, such as User Name, and then have that parameter limit the data in their Crystal report.  I have to admit this one has always been one of the items I always have struggled through, coming up with one alternative or another to meet the client needs.  Recently I was asked this same question by a support client of ours.  Together, we can up with a pretty lengthy Record Selection formula to achieve the desired results.  Not happy with how hard it was to achieve this I decided to dig into this issue again this morning and my results were surprisingly a lot easier then I ever imagined.

To prove my point follow along by creating a new Crystal report connected to your SalesLogix database,  The only table you need to add to this report is UserInfo and we only need one field, UserName.

There are three pieces to this puzzle.  The first is the parameter.

The parameter I created was labeled UserName, I changed the "List of Values" field to Dynamic, "Prompt with group text" I typed in UserNameList and then selected the UserName from the field drop down under the word Value. Other settings are "Prompt Text" = Select the Users you want to display in this Report, "Prompt with Description Only" is set to True, and the most important is "Allow multiple values" is set to True.

Next let's Create a formula field to see our results,  Name the field anything you would like and add the following as the formula.

Join({?UserName},",")

Now drag your formula field onto your report.  You should now be prompted by the report to select some users to display on your report. Select two or three to prove the point. When you close the parameter you will find you formula field is now populated with the names of the individuals you selected.  Each value is separated by a comma.

The final piece is the record selection criteria.  Remember the record selection criteria is set using the Report>Selections Formulas>Record menu item.  When the formula editor opens, add the following formula:

{USERINFO.USERNAME} in {@Test}

For your version of the formula, "{@Test} should be replaced with the your formula field.  When you close the editor you immediately see your list of users drop to the two or thee you had selected.

Embarrassingly easy stuff.  I hope this helps someone down the road. 

Thanks Geo

 

What's This?
Bookmark and Share

About George Jensen

   George Jensen is a Senior Developer for Customer FX Corporation.


Related Content
   Looking at Stonefield Query for Sage SalesLogix (Part 5)
Sorry for the long absence, I went away on some training with the Minnesota National Guard.  This is
Posted on Sep 01, 2010 by George Jensen to George Jensen's Blog
 
   Picklist Column types - Dispaying ticket status in the SalesLogix LAN datagrid
I recently had to build a datagrid displaying ticket information, including the current Status value. Un
Posted on Aug 24, 2010 by Jason Buss to Jason Buss' Blog
 
   SalesLogix Cloud- Administration Options- Using Roles
In this webinar the user will learn to manage roles in the SalesLogix Web Client. These options are onl
Posted on Aug 20, 2010 by Dale Richter to Free SalesLogix Training
 
   SalesLogix 7.5.2 Speed Issues - How To Find the Slowdown
At times I have been asked how can I increase the performance of SalesLogix. For systems using SQL2005
Posted on Aug 13, 2010 by Mark Duthoy to SalesLogix Support
 
   SalesLogix Cloud- Administration Options- Creating a New Team
This Administrative webinar will show the user how to create a new Team for ownership of records. This is
Posted on Aug 13, 2010 by Dale Richter to Free SalesLogix Training
 
Comments

 

Twitter Trackbacks for Using Multiple Value Parameters to Select Records for your Crystal Reports - George Jensen's Blog [customerfx.com] on Topsy.com said:

Pingback from  Twitter Trackbacks for                 Using Multiple Value Parameters to Select Records for your Crystal Reports - George Jensen's Blog         [customerfx.com]        on Topsy.com

December 8, 2009 11:55 AM
 

Clare said:

a string array is required in the Join function and apparently ({?UserName) is not recognised as a string array.

April 15, 2010 8:19 PM
 

Nissim Levi said:

This is very nice & elegant solution.

How About more complex requirements?

What if the parameter is multiple and dynamic, the value is code (number) and it presents also description. Now I want to present the user his selection (the descriptions only). how do you do that?

further more if the user select all the values in the list I want to present "ALL" in the report header. is there an elegant way to do that?

May 2, 2010 2:58 AM
 

Marjon said:

Well, that only one table and one record.

How about you make a report containing 5 related tables and make a three parameter fields and then pass to the crystal report viewer and generate the report.

June 11, 2010 4:20 AM
 

Curies said:

Well this work good or less good but still it work on side of crystal report. My question is how to workaround multiply values in the command/sql statment. U cant put parameter in query and make it multiple(I dont know why we have IN). We could workaround it if we would be able to change for example by formula parameter which goes to query(format it, or entire change it) Maybe I missing somethink if someone have solution on it please help me up.

July 27, 2010 9:06 AM
 

Kevin Suchlicki said:

@Curies

These will work for SQL Server.  Other DBs will have their own methods.  You have a couple of options for passing a multiple-value list to a SQL Server sproc:

1) Pass the list as a comma-separated string.  Then in the sproc, build your SQL as nvarchar and execute it dynamically using sp_ExecuteSQL.

CREATE PROCEDURE dbo.uspUsers

@UserIDList @nvarchar(max)

AS

BEGIN

DECLARE @SQL nvarchar(max);

SET @SQL = 'SELECT * FROM dbo.Users WHERE UserID IN (' + @UserIDList + ')';

EXEC sp_ExecuteSQL @SQL;

END

2) Pass the list as a delimited string (with no spaces, delimiter of your choosing... i like pipes), and use LIKE.  You need to be sure none of the values will contain the delimiter you choose in actual data.

CREATE PROCEDURE dbo.uspUsers

@UserIDList @nvarchar(max) -- example: asmith,jdoe,rbrown

AS

BEGIN

SET @UserIDList = ',' + @UserIDList + ',';  -- need to add the delimiter before and after the string for this to work correctly

SELECT * FROM dbo.Users WHERE @UserIDList LIKE '%,' + UserID + ',%';

END

The second method may be very slow if the table is large and the only filter you are using is the @UserIDList.  If you have other filters, like dates, then SQL Server can use those to narrow down the result set first.  

One trick you can use as a variation on the above is to generate a table in a subquery and join (you could also use "IN") that to a master table, which may be faster than using "LIKE" on the master table directly.  For example, if you wanted all the sales by some list of users:

SET @UserIDList = ',' + @UserIDList + ',';  

SELECT s.*

FROM dbo.Sales s

INNER JOIN (SELECT UserID FROM dbo.Users WHERE @UserIDList LIKE '%,' + UserID + ',%') u ON u.UserID = s.UserID;

The idea behind this is that string comparisons are slow but joins on indexed fields are fast.

August 13, 2010 9:18 AM

Leave a Comment

(required)  
(optional)
(required)  
Add
All contents Copyright © 2010 Customer FX Corporation
Customer FX Corporation
2324 University Avenue West, Suite 115
Saint Paul, Minnesota 55114
Tel: 800.728.5783

  Follow @CustomerFX on twitter
Follow the best news, tips, and articles
  Subscribe to Customer FX on youtube
Watch SalesLogix tutorial videos from Customer FX
Login / Register