Crystal Reports dynamic parameters values - crystal-reports

I have crystal report with dynamic parameter (for example, linked on table COUNTRIES in some datebase).
How can i programmatically get allowed values for this parameter (list of countries)?
For static i can get default values using :
ReportDocument rd = new ReportDocument();
rd.Load(reporthPath);
rd.ParameterFields; // contains params with default values collections
Dynamic parameters has no items in DefaultValues collection. I can retrieve existing connections for report, but where i can get relation between connection and dynamic parameters?

It's not possible to do that in Crystal Reports. It's better to not use dynamic parameter field; they make your report unnecessary slow. Instead convert them to a static parameter an fill the default values from your code; that's much faster plus you know what the accepted values are.

the above answer is incorrect - as of Crystal Reports XI (at least that's where my information comes from) it is possible; see
http://devlibrary.businessobjects.com/BusinessObjectsXIR2/en/en/CrystalReports_dotNET_SDK/crsdk_net_doc/doc/crsdk_net_doc/html/crtsktutorialsrdparametersdiscrete.htm, particularly parts 2(Creating a Report with Parameters) and 5(Create a ListBox Control that Displays Default Parameters)
basically the list of possible values can be taken from the default values list,
thanks,
MD-Tech

Improving on the existing answers a little bit after running this problem to ground myself:
A ParameterField with a Static list of values has these values as items in its DefaultValues collection. The problem is that a ParameterField with a Dynamic list does not have these values pre-populated and the API does not seem to have a mechanism to query them.
A workaround involves using a Static list instead of a Dynamic one, but there may be hundreds of acceptable values which may change over time. Unless remembering to change the report(s) is appealing, a Dynamic list makes sense in this context.
In addition, using the CrystalDecisions.ReportAppServer.DataDefModel.ParameterField reveals a property BrowseField. BrowseField has properties TableAlias and Name which you can query with ADO.NET. However, BrowseField is only populated for Static parameters; it is null when using a Dynamic parameter. This is currently documented as a "needs fixed" on SAP's knowledge base, Article 2114469.
So, once you somehow get the table and column name, use ADO.NET to query the database and stick those values into the DefaultValues collection of the Dynamic parameter. Consider using a naming convention for the parameters to make this easier. Perhaps use a static parameter that isn't used in the report to house your table and column information.

Related

Prioritise which identifier to use

My crystal report pulls data about books, including an identifier (isbn, issn order number etc.), author, and publisher.
The ID field stores multiple ways to identify the book. The report displays any of the identifiers for that record. If one book has two identifiers; issn and order number, the report currently displays one apparently at random.
How can I make it prioritise which type to use based on a preset order? I figured some sort of filter on the field could work, but I haven't figured out how. I can't edit the table, but I can use SQL within the report.
If all the different types of ID are stored in a single field, your best bet is to use a SQL Command inside your report to separate them into multiple virtual fields.
Go to Database Fields / Database Expert, expand the connection you want to use, and pick Add Command. From here you can write a custom SQL statement to grab the information you're currently using, and at the same time separate the ID field into multiple different fields (as far as the report will be concerned, anyway. The table will stay unchanged.)
The trick is to figure out how to write your command to do the separation. We don't know what your data looks like, so you're on your own from here.
Based on the very little information that you have provided and if i was to make a guess.I suggest you make use of the formula field in your report and then use something like this to accomplish your goal.
IF ISNULL{first_priority_field_name} OR {first_priority_field_name} = '' THEN
{second_priority_field_name}
ELSE
{first_priority_field_name}
Use nested IF statement in case there are more than 2 identifier fields.

SSRS field scope issue

I have an SSRS 2008 R2 report that uses this expression in a table:
=Lookup(Fields!DataSet1Date.Value, Fields!DataSet2Date.Value, Fields!DataSet2Price.Value, "DataSet2")
I have 2 data sets and am using the Lookup function to get data from one dataset based on the date in another dataset.
My problem is that this works on machines that I have tried it on, but others are getting errors like this:
Error 1 [rsFieldReference] The Value expression for the text box ‘Col_D2Price’ refers to the field ‘DataSet2Date’. Report item expressions can only refer to fields within the current dataset scope or, if inside an aggregate, the specified dataset scope.
Error 2 [rsFieldReference] The Value expression for the text box ‘Col_D2Price’ refers to the field ‘DataSet2Price’. Report item expressions can only refer to fields within the current dataset scope or, if inside an aggregate, the specified dataset scope.
What other things can we do to troubleshoot this issue? We are all using the same 2008R2 version.
I oftern get this "phantom" error when using the LookUp function. I call it phantom as no where can I find a reason, but there you have the error pop up.
The only way to get around it in my cases is to use the secondary function LookUpSet.
Hope I've helped.
Edit:
Furthermore you've intrigue me so I've done some research:
The lookup function is only for 1-to-1 relationship.
The loopupset funcrion is for 1-to-many relationship.
The multilookup function is for many 1-to-1 relationships, i.e. an array of single values where there is only 1 value in the second dataset. Not relevant but quite interesting.
Also I came across a potential fix. This being on the new machines try and open the datasets in the report and refresh all fields in the dialog box. For some reason this may relink the fields to this expression. Go figure...Blockquote

JasperReports: dynamic report generation

I am new to JasperReports. I need to design a report where certain columns and rows are dynamic. For this how I have to design the report and after design i want to integrate with my application for fetching data from action class and dto. How to map data for its?
I don't know how dynamic it will be, but it may help you: http://dynamicjasper.com/
It uses JasperReports to generate your report and it also allow you to create your report on the fly.
There are 2 options to map data with the columns. First option is u can pass ur data into data Source binding with the column name as key value pair. And the second option is u can pass the obj of your dto to data source directly in list form.
Use report.setDataSource() for setting the data. In first option make sure your type of the data matches with the column name.

Create Formula Field that Lists All Tables In Crystal Report

I am looking for a way to create a formula field that will list out the table names of all tables that are being utilized as data sources in a Crystal Report.
I have not found any function that provides that capability in the application yet.
This would be used to put the list of tables as a supplemental for those users that do not have access to the report file but need to know what tables are used in the report.
It seemed better to do this as dynamically as possible - instead of having to provide a static list of current tables linked into the report.
Thanks.
Unfortunately, this type of functionality isn't present in Crystal Reports.
You might be able to use a UFL to solve the problem. General idea:
pass path of current report to UFL (the Filename function will give you this)
open the referenced report using the Crystal Reports SDK and examine the tables in DataDefintion class; the DatabaseFieldDefinition.UseCount will help determine if a field (and hence table) is referenced in the report
return the table names as a string array (note: CR only supports 1-dimensional arrays w/ a maximum of 1000 elements)
create a formula field to call the UFL's function; Join() the string array (formula fields can't return an array):
Join(GetRptTables(Filename), ",")
distribute the UFL with the .RPT
Another option, if you have BusinessObjects Enterprise and a spare $40K, is Metadata Manager; this will give you a holistic view of your organization's reporting deployment.

Selection Formula Pass-through not working with SQL Command Object

I'm using Crystal Reports XI. We use Crystal Reports embedded into a share point site written in C#/ASP.net. Our web developers instatiate a report in code and pass the selection criteria by appending to the Select Formula object.
The problem I'm running in to is that when I use a SQL Command Object, the selection formula is not being passed to the sql server as a where clause. This causes the entire result set to be queried and then limited on the server. For very large tables, this is causing a significant performance hit.
Here's an example:
SELECT foo.id, foo.code, foo.name
FROM foo foo
Select criteria is shown as:
{Command.name} like "someName"
If I then run the report the entire foo table is queried and then crystal reports limits from the entire set.
If instead I do it based on the table without a command object, the WHERE clause is appended to the sql query and all the limiting is done at the db level.
I'm assuming this occurs because a SQL command could potentially be very complex and adding a WHERE clause to the bottom isn't always possible. My question then, is there any good way to force some sort of pass through. Should I be talking to the C# devs and asking them to rework the way we pass parameters?
Thanks for any help and discussions.
A record-selection formula is never added to the Command-object's query.
I'm not certain if the CR SDK supports Command object modification (I know it supports read-only access, however).
The Command object does support parameters (in 2008, they can be multi-valued parameters) which can be accessed programmatically (they are converted to Parameter Fields in the report).
I'm assuming that you are using a Command object because of the query's complexity. If you can push the complexity to a SQL view, then use the 'visual linking' expert to create your query, you'll have more flexibility.