Generate a report using jasperReport contain no available data - jasper-reports

I'am using JasperReport and ireport 4.0
I want to generate a report contain the word "no available data for this request" When the request do not return data.
How can I do that?
than you

Rym, you can set "When No Data" template property to "No Data Section" value (in IReport). And then add Static Text (to this new band) with "no available data for this request" text, for example

You can do as Alex K said, or better check if you have any data to process before generating the report, then you can generate another simple report saying "no available data ...", I guess you can save much on computing resources doing it this way.

Related

JSON schema validation failed: resource: String does not match pattern:^/[^/~!#\$%^|\s`#&*()\-+={}\[\]:;"'<>,?/\|\\]+(/[^/~!#\

I'm trying to embed Jasper Reports into APEX App. I'm able to gather reports from samples (samples on JasperCommunity website), however, when I'm trying to get created by me and colleagues reports - every time I have the same error:
JSON schema validation failed: resource: String does not match pattern: ^/[^/~!#\$%^|\s#&*()\-+={}\[\]:;"'<>,?/\|\\]+(/[^/~!#\$%^|\s#&()-+={}[]:;"'<>,?/\|\]+)$.
In other words I can't get any of our reports apart from the samples (e.g. /public/Samples/Reports/03._Store_Segment_Performance_Report"). I think the case is that the path to the Report is wrong, but I've tried all possible and impossible options and none of them works. Anyone any ideas please ?! Thanks
P.S. APEX 4.2.6, JasperServer 6.0. And finally, I can get samples Reports ONLY under the JasperAdmin user, simple User always got an error - 'Access Denied'. Why ?!?!?!
Sorted.
If anyone interested - when specify the actual path, in Jasper: right click on Report(or Dashboard, AdHocView etc.) and copy the path from it. As it differs from when you point mouse on it (e.g. adding the underscores etc.), and paste this actual path into your javascript code into HTML section in your web app. Thanks

How do you put a version number into an rdlc file?

I've a couple of rdlc files which I change everytime business has additional requirements. The problem is that we keep pdfs of the reports we create, and it's impossible right now to see what version of the rdlc file it was created with.
I've thought about putting a text field with "Version XX.Y" into the footer, but then I have to remember to update this when I make changes. It's not the worst solution in the world, but I'd like to hear how others handle report versioning in reporting services.
Note that I am renedering reports using local reporting, i.e. no server, so I've thought about somehow trying to display the assembly version of the application running the report. This I can control more easily with .* notation in assemblies, but I'm not sure how to have a text field which would show this.
You could add a property containing the assembly version to the report's data source (or pass the value in some other way).
public string AssemblyVersion {
get {
return Assembly.GetAssembly(typeof(WhateverTypeThisIs)).GetName().Version;
}
}
Another option might be to use an MSBuild task to replace the version number in the .rdlc for you. XMLPoke, for instance.
If you are using subversion, an option might be to use the SvnInfo task from MSBuild community tasks to get the last changed rev of the report and use that number to update the XML of the rdlc file.

Why do I get "Database logon failed" in Crystal Reports when using .NET object as datasource?

I am creating a simple report using a .NET object from my project as datasource, using SetDatasource() method. However, when I run the report I get "Database logon failed" error. This report is not connecting to a DB at all - have I missed something here?
Many thanks,
D.
ADDED:
I guess it will probably help if I include the Controller action. It's a quick and dirty test, not what the final method will look like:
public ActionResult StewardSheets(int showId, int groupId)
{
ReportClass rptH = new ReportClass();
rptH.FileName = DataHelper.getReportFilePath("Test.rpt",this);
NZDSDataContext dataContext = new NZDSDataContext();
var showDetails = (from s in dataContext.Shows
where s.ID == showId
select new StewardSheetModel
{
EventDate = s.EventDate.ToLongDateString(),
Region = s.Region.Name,
ShowTitle = s.Name
}).FirstOrDefault();
List<StewardSheetModel> details = new List<StewardSheetModel>();
details.Add(showDetails);
rptH.SetDataSource(details);
rptH.Refresh();
Stream stream = rptH.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
return File(stream, "application/pdf");
}
FIXED:
D'oh! I used ReportClass instead of ReportDocument. Changed that line, and also use Refresh() since Load() is not a valid method. Now it works just fine!
If you are using ADO.NET DataSets as your datasource, it is possible for the DataSet definition to get out of sync with the definition in the report. Selecting the Database->Verify Database option from the report designer's context menu will often fix this problem.
Also, you will get this error if your report has linked tables and you fail to set the datasource for one of the tables. The fix is either to remove the table from the report, or set it's datasource correctly.
For example, if your report has a Customers table and an Orders table linked together on some key you will need to set the datasource for both tables. If you forget and set only one, you will get a "Database logon failure" error which is fairly misleading.
// Create a new customer orders report.
CustomerOrdersReport report = new CustomerOrdersReport();
// Get the report data.
DataTable customersTable = getCustomersData();
DataTable ordersTable = getOrdersData();
// Set datasources.
report.Database.Tables["Customers"].SetDataSource(customersTable);
report.Database.Tables["Orders"].SetDataSource(ordersTable ); // Don't forget this line like I did!!
Please try, Right-Click on Report -> Database-> Verify Database.
If dialog box appears, locate your DataSet .xsd file (e.g DataSet1.xsd) and Apply.
My problem solved in this way.
I started getting the notorious "database logon failed" error on a Windows Server 2016 machine after the July 2018 windows server updates. The report ran fine in Visual Studio 2017 on my dev machine, but not in IIS on Windows Server 2016 in production.
After a day of investigation, I installed the Microsoft OLE DB Driver for SQL Server on my development machine - https://learn.microsoft.com/en-us/sql/connect/oledb/oledb-driver-for-sql-server?view=sql-server-2017. I created a report connection in the Crystal report database expert using the MSOLEDBSQL provider. I had to install the Microsoft OLE DB Driver for SQL Server on the production Windows Server 2016 machine as well.
It turns out Microsoft has decided to deprecate the Microsoft OLE DB Provider for SQL Server. This and the native client no longer seem to work with Crystal Reports.
I was struggling with this error for a couple of days. I have a .NET webforms project which uses CrystalReportViewer to load a Crystal Report. Instead of the report loading, I kept getting "Database logon failed".
I opened the RPT file in Crystal Report Designer and went to Database -> Verify Database
This gave me a more specific error. FINALLY!!!
I tracked down the XSD file, moved it to the right location and BOOM
I started getting this dialog popping up after I changed the name of the .NET object my reports were referring to. To get rid the dialog, I had to ensure that none of my report sections or fields referred to the old name of the .Net object which was easy to spot. The fix for me was using the rename function in the Database Expert for the report.
Fixed by using the appropriate class: ReportDocument instead of ReportClass.
One of the reason of this error is, when u pass null object to a sub report
....SetDataSource(data) , where data is null
I had to do write the below line of code to get rid of the "Database login error"
CrystalDecisions.Shared.TableLogOnInfo li;
li.ConnectionInfo.IntegratedSecurity = false;
Mine did it when I was sending in a DataSet instead of a DataTable.
ReportDocument.SetDataSource(dataset.Tables[0]);
In my case i forget to set datasource to a datatable.
something like this
rpt.Database.Tables("Account").SetDataSource(CType(DataSource.Account, DataTable))
Use native client Connection Version 10.
I hade the same problem and it was due to the fact that I accidentally added anoher DataTable with the same name.
var ds = new OrderDetail();
var dt = new OrderDetail.ResultDataTable();
//fill dataset here
ds.Tables.Add(dt);
After setting that DataSet as datasource I got the login failed error when exporting the report.
I then added a line to remove the DataTable before adding the new DataTable:
ds.Tables.Remove(dt.TableName);

Localized Crystal Reports

What is a good method to localize labels (column headings, field labels, headers/footers, etc) on Crystal Reports?
We are currently on XI R2 SP4 but are looking to migrate to 2008. It looks like 2008 offers better localization of the viewer UI. Does it have a content localization story?
Found a way to for localization of values such as DateTimes in Crystal Reports.
For instance if date is Aug-2009 and culture is French then would display as août-2009.
All this WITHOUT switching the current Thread culture to French.
Relevant Code snippet (example):
//Locale must be set BEFORE report is opened
if (this.IsEnglish)
{
ReportDoc.ReportClientDocument.PreferredViewingLocaleID =
CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleEnglishCanada;
ReportDoc.ReportClientDocument.LocaleID =
CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleEnglishCanada;
ReportDoc.ReportClientDocument.ProductLocaleID =
CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleEnglishCanada;
}
else
{
ReportDoc.ReportClientDocument.PreferredViewingLocaleID =
CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleFrenchCanada;
ReportDoc.ReportClientDocument.LocaleID =
CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleFrenchCanada;
ReportDoc.ReportClientDocument.ProductLocaleID =
CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleFrenchCanada;
}
//Load the report from file path
ReportDoc.Load(reportPath.ToString());
The two options that I can think of are: 1) Have a separate report for each localized version (this gets ugly quick and I don't recommend it very highly) or 2) Have the report generated from an application (say a c# windows/web app) and then you can localize using .net's localization standards and setting all of the localized text (read in from resource files) in the code.
I am not certain about 2008 but we are also on XI R2. We have localized reports for each language but only because we * know * that we will only need three different localized versions.
A client asked me to do develop a localization strategy for them. I've been meaning to write an article on it. Thanks to you, I've done just that. http://www.cogniza.com/blog/?p=55
Edit:
I was able to use an embedded subreport (in the report-header section) that referenced a database of localization values. I would have added that to my posting, but it was quite complex.
Another option is to create a user-function library (UFL) that handles this tasks. Store the data in a database or XML file. Most likely, however, you will lose the ContentLocale functionality.
We finally got around to implementing report localization. Loading of Crystal Reports is already the laggiest/worst-performing part of the user experience in our app, so we wanted to avoid any performance impact. The other idea that informed our decision was that the translations won't change within a shipped release.
We developed an application that uses the Crystal Reports API (2008 - so there's no RDC) and works in two phases.
First phase is to scrape all of the text and output to an English .resx file. Toughest part of this is identifying translatable text within functions, and replacing embedded fields with tokens indicating "don't translate."
After the localized versions of the resx come back, the second phase of the app takes each report along with each resx and saves out new reports with English replaced with translated text. This also allowed us to switch out the fonts only in Japanese reports to MS Gothic, thereby avoiding the need to license a "universal" font. The Japanese characters in "universal" fonts (e.g. Arial Unicode MS) tend to look like crap.
The Crystal API is byzantine, and you need to be careful with edge cases around detecting translatable strings within functions and embedded fields. Be careful with the builtin fields like PageNofM, they aren't enclosed in curly braces (not to mention that you should replace this with Page {field} of {field} so "page" and "of" can be translated). One pointer, use the controllers to replace existing items with cloned/modified copies, you can't just modify the text content of items in place. Good luck if you go this route, but in the end we think it's the best option.
Single Crystal report Use for multiple language
if (CultureInfo.CurrentCulture.Name == "en-US")
{
(obj.ReportDefinition.ReportObjects["lbleverest"] as TextObject).Text = resBundle.GetString("Localization", "everest");
(obj.ReportDefinition.ReportObjects["lblmandlicode"] as TextObject).Text = resBundle.GetString("Localization", "SocietyCode");
(obj.ReportDefinition.ReportObjects["MandliName1"] as FieldObject).ApplyFont(new Font(resBundle.GetString("Localization", "Font"), Convert.ToInt32(resBundle.GetString("Localization", "FontSize")), FontStyle.Regular));
(obj.ReportDefinition.ReportObjects["shortName1"] as FieldObject).ApplyFont(new Font(resBundle.GetString("Localization", "Font"), Convert.ToInt32(resBundle.GetString("Localization", "FontSize")), FontStyle.Regular));
}
else
{
(obj.ReportDefinition.ReportObjects["lbleverest"] as TextObject).Text = resBundle.GetString("Localization", "everest");
(obj.ReportDefinition.ReportObjects["lblmandlicode"] as TextObject).Text = resBundle.GetString("Localization", "SocietyCode");
(obj.ReportDefinition.ReportObjects["MandliName1"] as FieldObject).ApplyFont(new Font(resBundle.GetString("Localization", "Font"), Convert.ToInt32(resBundle.GetString("Localization", "FontSize")), FontStyle.Regular));
(obj.ReportDefinition.ReportObjects["shortName1"] as FieldObject).ApplyFont(new Font(resBundle.GetString("Localization", "Font"), Convert.ToInt32(resBundle.GetString("Localization", "FontSize")), FontStyle.Regular));
}
obj.DataDefinition.FormulaFields["lang"].Text = "'" + CultureInfo.CurrentCulture.Name + "'";
cv.crystalReportViewer1.ReportSource = obj;
cv.Show();

How to troubleshoot "DataMember Not Found" in ActiveReports

ActiveReports seems like a powerful flexible tool, but if you make a mistake anywhere, you get an exception "data member not found. please check your datasource and datamember properties".
There is no indication as to which datasource/datamember is at fault or what subreport the problem lies in, but Active Reports must know this!
The stack trace is no use, as the error is thrown after the report.run() method is invoked from deep within code generated by Active Reports itself.
Does anybody have a solution other than commenting out one subreport after another and checking all fields in turn?
I was getting the same error while trying to pass a raw dataset to a report as below:
...
Dim rpt as New ActiveReport
With rpt
.DataSource = _data
.Run()
End With
...
I specified a table in the dataset and the error went away.
...
.DataSource = _data.Tables(0)
...
`
Unfortunately I don't know a way to immediately tell which subreport that error is coming from. Indeed, that error message should be improved when you're using subreports. I will report it to the ActiveReports development team.