Limit the number of Multivalue parameter selections SSRS - visual-studio

I have a report with a parameter with about 12 multivalue parameters. Is there a way to select 5 parameters and when selecting the 6th parameter displaying 5 is the limit ??
Any ideas are appreciated.

As a work around , you could try using a combination of a visibility expression to count the parameters chosen and a separate text box with a warning message, such as :
=IIF(Count(Parameters!XYZ.Value(0),"DataSet1") > 5 , "too many parameters selected", "ok")
and using a variation of the expression to hide / show your original report.

There is no way to give immediate feedback when the limit is exceeded. One option would be to show a message once they click the View Report button. It's a bit of a workaround, but you would have to have the dataset return no rows. Then for the message, you could either have a texbox with conditional visibility somewhere on the report OR you could use the NoRowsMessage property on a table to show the appropriate message.
If you have a more complex situation such as multiple parameters, you can just add in more conditional logic to the dataset and message to check if all the conditions are met and which message should appear.

Related

Crystal Report not filtering SQL records based on selection formula

unfortunately I'm not an expert of Crystal Report, so I'll post here my question hoping for any help about my issue.
I want to display inside my report the result of a filter on a SQL RecordSet; this RecordSet is looked up from an a single table, of which I want to show some fields of my SQL table, while the filter I want to apply is based on a field parameter (defined static) that I'm trying to set programmatically.
Here below I attached my code where I'm applying the record selection formula, I tried also hard-coding the value instead of passing it through a dropdown selection:
ReportDocument RPT_Doc = new ReportDocument();
RPT_Doc.Load(RPT_Path_Name, OpenReportMethod.OpenReportByDefault);
ApplyConnInfos(ref RPT_Doc);
RPT_Doc.SetParameterValue("data_riferimento", "20161001");
RPT_Doc.RecordSelectionFormula = "{viaggi.data_part_pre} = '20161001'";
crystalReportViewer1.ReportSource = RPT_Doc;
In the first image attached you can find the field parameter definition, while second image is the record selection formula I defined inside my report:
The report always shows all the records of my table (more than ten thousand rows), instead of displaying a filtered RecordSet. The odd thing is Preview function from Visual Studio works like a charm; it prompts the field value, once I confirm the value the viewer displays the report with the rows filtered as I expect..
What am I missing from report/C# program configuration to make the record selection work?
Thank you in advance for any suggestion you can give me :)
Leonardo
Ok, finally we got the solution to our issue.
We found the CrystalReportViewer object used to display generated reports has 2 different properties, SelectionFormula and ViewTimeSelectionFormula; both has default value set to empty string.
Below I attached the picture of .Designer.cs file with the 2 properties valued:
We commented those 2 properties and the selection formulas and field parameters applied through code / report designer worked again.

Use SSRS Expression to Hide Tablix Based on Parameter Selection

I have a report that displays sales by county or by agent - but the user cannot select both. The #AgentOrCounty parameter is hard-coded: Agent = 0 and County = 1. And the #AgentID parameter only accepts one value but the #CountyID accepts multiple values. And my report has two tablixes: one for the dataset and one to display an error message if the user selects both an #AgentID and #CountyID
What I hope someone can help me with is how I can write two expressions to hide the tablixes based on the user selection.
One additional issue I am experiencing is that the #CountyID parameter is a multi-value parameter that I have to pass a NULL value to to allow the report to run if the user wishes to display by Agent.
Right now, on my Error Message tablix, I have the following expression:
=IIF(LEN(Parameters!AgentOrCounty.Value)=0,TRUE,FALSE) OR IIF(LEN(Parameters!AgentID.Value)=0,TRUE,FALSE)
But this doesn't hide the Error Message tablix when the user runs the report correctly for Agents.
When I think in logical terms, I would like the Error Message table to be hidden if the #AgentOrCountyID = 0 and #CountyID is NULL or the #AgentOrCountyID = 1 and #AgentID is NULL.
And I would like the report data tablix to be hidden if #CountyID and #AgentID are both not NULL.
Any suggestions?
To hide the error message tablix, I used the following expression:
=IIF((Parameters!AgentOrCounty.Value=0 And Parameters!CountyID.Value(0)="NULL")
Or (Parameters!AgentOrCounty.Value=1 And Parameters!AgentID.Value Is Nothing),True,False)
And to hide my data set tablix when the user selected both an agent and a county, I used the following expression:
=IIF(Len(Parameters!AgentID.Value)>0 And Len(Parameters!CountyID.Value(0))>0,True,False)

Jbo-25089: Too many matching records found. Specify additional criteria to limit the number of records

I have a LOV in the UI. Upon clicking it, it shows the values in it. Upon selecting a particular value in that LOV, the error pops up saying that:
Too many records found with matching criteria.
This happens only for the first value that I am selecting from the LOV. If I select a different value from the LOV again, this error doesn't appear.
The range size of the iterator that this LOV uses is 25. I have used the preferred tuning settings in the VO to which the LOV belongs. Please help me in understanding why this is happening.
Thanks in advance.
It occures when there is a duplicate record in viewObject for same attribute, Is there any other record in that VO ?

IIF Statement in TablixFilter issue

I'm trying to filter a matrix in my report. I have names of 4 drivers and I want the Matrix5 to show the name of a default driver in case SELECT ALL is checked in filter. Otherwise I want the matrix to show whoever is checked.
I set an expression at matrix filter as;
=IIF(Parameters!Sofor.Count=4,"abcdef",Parameters!Sofor.Value)
-abcdef is the name of the default driver for the tablix
-Sofor is the driver name parameter and has 4 total possible name options, 5 if we consider SELECT ALL too.
It works well if I check SELECT ALL but stops working if I select only one option.
Error I'm getting is as follow;
"The processing of FilterExpression for the tablix "Tablix5" cannot be performed. Cannot compare data of types System.String and System.Object[]. Please check the data type returned by the FilterExpression"
Though the error sounds pretty self explanatory I still can't understand what I'm doing wrong. Any help please?
Parameters!Sofor.Value is an array of values (the object) because its a multi-select parameter. (what happens when the user chooses 2 drivers?)
Try
=IIF(Parameters!Sofor.Count=4,"abcdef",Parameters!Sofor.Value(0))

Browse field data shows value, but displays another value

I have a formula written for a field in Crystal Reports. When i refresh the report, i get a different value from the formula. The required value is always the last value in Browse Field Data dialog for that formula.
Isnt the formula supposed to have only one value as output? why are multiple values shown in browse field data dialog.? Is there a way to retrieve last value of Browse File Data dialog?
My formula looks like below:
WHILEREADINGRECORDS;
NumberVar CODTOTAL;
if {XXX.YYY} = 1 then
( CODTOTAL := CODTOTAL + {XXX.ZZZ};
);
CODTOTAL;
Browse field data shows all the values "CODTOTAL" acquires as a result of that formula and displays a random value amongst the assigned value.
Please help me out. I am amateur in crystal reports.
Any help would be highly appreciated.
~Regards.
First observation should be where have you placed the formula (Details, Footer.. etc).
why are multiple values shown in browse field data dialog.?
Browse field shows the data that is present in the table but in your case you are applying "If" condition of the filed. It can be possible that there is only one record that satisfies your condition.
I would suggest to run the report without the codition, Check the results and apply the condition and check results again.

Resources