'This field name is not known' error (Crystal Reports) - crystal-reports

Here is a strange problem I have run into.
My record select formula is as follows, I have dumbed it down for purposes of this error:
reportDocument.RecordSelectionFormula = " {#ClientName} = 'Smith' "
If I copy this exact selection statement into Crystal it previews fine, but when run from .NET I get
'This field name is not known'.
The problem is occurring at the #ClientName formula field.
#ClientName simply contains:
formula = {aw_illust.CL1LNAM}
I can also set it to just a blank string (formula = "") and it still gives
'This field name is not known.'
Here is the strange part, if I bypass the formula and put the formula text straight into .NET everything works fine.
reportDocument.RecordSelectionFormula = " {aw_illust.CL1LNAM} = 'Smith' "
That is the same record selection, except with the '#ClientName' formula replaced with '{aw_illust.CL1LNAM}'. It just happens on this one report, I have many other Crystal Reports working with formulas referenced in .NET just fine. Any ideas?

Most likely you are not using your {#ClientName} formula anywhere on report; Crystal Reports tends to ignore unused fields, formulas etc. Place {#ClientName} field somewhere in report (header or some similar section) and suppress it - this way you don't mess up report design, but CR should know about that formula afterwards.

Which syntax has the formula? If it is crystal syntax then change it to basic syntax. Or change the content of the formula to crystal syntax (without "formula =")

You could create a parameter like {?ClientName} and set that from .NET, and then put a select formula in Crystal like {#ClientName} = {?ClientName}.

Can you save the report with the selection criteria you'd like then display what the reportDocument class sees using something like:
TextBox1.text = reportDocument.RecordSelectionFormula
This would confirm that your syntax is correct.

Same happened with me when I copied existing report to be used as the new one, You can first open report in report viewer ,In my case
but the query that loading report has no selection with name DateLocal Transaction so I got this error, the resolve is to either use only those that are require (Extras has nothing to do with the error) or rename selection value in query.

Related

How to do conditional sum in Crystal Report

Question originally posted in Spanish, on es.stackoverflow.com, by Sebastián Miranda:
I am working with Crystal Report since Visual Studio 2017, I was asked
to make a sum to group, I have 3 options: Credit Notes, Ballot and
Invoice.
The first thing I did was to create a Formula Field with the name
NumberValorCif to convert the ICIF Value that I have to numeric with ToNumber (). I saved this and created another formula field
named SumCIFCredito that has the following code:
If {CobroPorcentaje.TipoDoc} = 'Credit Notes'
then {#NumberValorCif}
else 0
I saved, compiled and ran the application and it worked without any
problems ... but. I wanted to do the same for SumCIFBoleta:
If {CobroPorcentaje.TipoDoc} = 'Ballot'
then {#NumberValorCif}
else 0
But I don't add anything. I'm missing something? or I have to create
another variable.
I hope someone can help me.
Thank you so much
It sounds like you simply need to add the actual SUM of that new formula.
Place the new formula in the detail section, select it, hit the Sigma button to sum it, and elect to generate subtotals for your Grouping level.

Crystal Reports Selection Formula If No Match Then

I currently have a Crystal Report with a selection formula that looks like this
{dbo.CustomerName}={?CustomerName}
AND
{dbo.Opportunity}={?Opportunity}
An issue that I'm finding is that sometimes there isn't a matching customer name, but the report still needs ran on the subsequent selection formula. Is there a way to create an IF THEN statement that says something like:
IF IsNull({dbo.CustomerName}={?CustomerName})
THEN
{dbo.Opportunity}={?Opportunity}
ELSE
({dbo.CustomerName}={?CustomerName} AND {dbo.Opportunity}={?Opportunity})
Obviously the IsNull operator requires a field and not a statement, but I'm not sure how to accomplish what I'm trying to accomplish
The following should work:
(IsNull({dbo.CustomerName}) AND {dbo.Opportunity}={?Opportunity})
OR
({dbo.CustomerName}={?CustomerName} AND {dbo.Opportunity}={?Opportunity})

Issue with passing field variable to subreport from master report

I am trying to do a simple expression in iReport, but whatever I try seems hasn't given me which I expected. It seems like such a simple thing to do, but I couldn't understand what's happening with my code.
All I'm trying to do is show a subreport when the value of an string field is a simple word like "VALUE". I am using the Print When Expression for the subreport control, however I'm not able to the see or reproduce this text with this expression. For me seems that I'm not passing well the parameters I wan't to use to do the print when expression in the subreport from the master report.
Is a disclaimer, so in master report I have a simple subreport, with the same conection from master and one parameter called Entity = "_id.Entity" (we use mongodb to get the fields for the report with a $group) and in the subreport part I have 2 text fields, the first one have the print when expression when P{Entity}.equals("VALUE"), the second one don't have any condition so this works perfectly, but the textfield with the condition doesn't work.
Any help would be appreciated. Thanks.

Crystal reports no data lable

I have a report containing some sub reports and in my main report i am showing the sub reports based on scan mode and status coming from query.
Now i need to show a message whenever sub reports don't have data.
I tried like this.
checked supress blank sub report and supress blank section for all reports.
1.Kept a text box in report footer of main report.
2.Took a field (Say Barcode) from sub report and passed to main report using shared variable.
3.In section expert of text box wrote like this.
not isnull(Barcode)
But it is not working.
Please suggest.
If I have understood this correctly the code below should work. Tip, avoid using NOT ISNULL. If possible just change the outcome order of your IF statement as below.
To make your formula more robust also, it's a great idea to add in the:
OR = ""
To account for any blank entries.
Final code:
IF Isnull({Barcode}) OR {Barcode} = "" THEN FALSE ELSE TRUE

"Document has no pages" on iReport and nothing on OpenReports

I am having an issue with JasperReports I can not solve. I am using Eclipse, OpenReports 3.2 and IReport 3.7
The issue I am having is that the report does nothing. When I preview the report in IReport I can at least get a "Document has no pages" message but when I try to open it using OpenReports it doesn't do anything. I get the open reports header and the copyright message but nothing between them.
I was able to track it down to line 150 in ReportRunAction.java in OpenReports. That line is:
jasperPrint = jasperEngine.fillReport(reportInput);
At least that is the line the page dies on. It trips the catch block that the line is inside of but the error is empty. When I try to print the description it is null. I can't swear that the issue isn't that parameter. Through looking around all I have been able to find is something about how the report needs to be compiled with the same version of the jasperreports.jar that OpenReports uses. I have no idea how to tell if/what version of jasper reports is being bundled into the .jasper file though.
Is that my problem? If so how do I tell/set the version of the jar that gets bundled? If not; help!
The no pages messages comes out when the report has not records or you discarded all of them with a wrong filter expression.
There are a couple of things you can try:
set the filter expression to:
new Boolean (true)
This will in some way reset your filter expression.
Right click your jasper report
properties
find more...
and Set the report property "When no data" to "All sections no details" so you can see at least the rest of the report.
Thanks.
If you are using the Detail Bandeport, then you will need a Data Query for the report. Since it's returning "No Pages" in iReport, then you either don't have a query. Or simply your query is not returning any rows.
In old iReport, from Data menu, choose Report Query and write your query here. If you want only one record (i.e. Detail band only one time) you can use a dummy table. Like:
SELECT 'a' FROM DUMMY
Otherwise, if you don't want to use the Detail Band, you have the option to view the other bands without using a query. From Edit menu, choose Report Properties, under More... tab, set the flag When no data to All Sections, no detail
Your problem is not exceptions or errors, it's just no data to show.
Any Empty Datasource will do the trick too.
I ran into the same error when using IReports when I had a subreport that only contained other subreports and no actual query. Adding a dummy query as medopal suggests fixes the no pages error and allows things to run correctly.
See also: http://jasperforge.org/plugins/espforum/view.php?group_id=83&forumid=101&topicid=49315
I've been facing this error for a while. In my case, this error occurred because of an image. If you have images in your report file, you will be forced to fill image with valid data when you wanna use report. If you don't, you will see this error "Document has no page". To address this problem just set "on error type" field in properties window (just click on image you'll see the property window) to "blank".
Strong wish.
I had same problem and got after searching problem, that I did not provide password to connection.
so I add these lines to my java code.
Class.forName("com.mysql.jdbc.Driver");
con =DriverManager.getConnection("jdbc:mysql://localhost:3306/stock_mngt","root","your password");
now my code works.