2018.1.2 How to add JSON data?

Stimulsoft Reports.WEB discussion
Post Reply
shadowkras
Posts: 27
Joined: Wed Jan 30, 2013 10:53 am
Location: Cuiabá/Mato Grosso - Brazil

2018.1.2 How to add JSON data?

Post by shadowkras »

I recent upgraded my project from 2017.1 to 2018.1.2, and Im having trouble trying to add JSON data into my reports.

The old GetReportData method is gone and now we can create and access StiReport (thank you), but I cant figure out which methods to register data into my reports. I tried the following:

Code: Select all

               var StiReport = new StiReport();

                #region Layout

                var relatorio = _repositorio.ObterLayout(formulario, sequencia);
                StiReport.LoadFromJson(relatorio); //This loads my .mrt file, and is working as Intended

                #endregion

                StiDataCollection collection = new StiDataCollection();

                #region Carrega Ambiente

                var Ambiente = _ambienteRelatorio.ObterAmbienteRelatorio(empresaId: 1);
                StiData _ambiente = new StiData("Ambiente", Ambiente); //Ambiente is a JSON object

                collection.Add(_ambiente);                

                #endregion

                StiReport.RegData(collection);

                return StiNetCoreViewer.GetReportResult(this, StiReport);
Before the report loads (before GetReportResult), I check the datasources of my report and my information is there. However, after the report is rendered, I get either error 500 (Internal Server Error) when using the Designer, or error 404 (Not Found) when using the Viewer.

I attached some sample data, but im not loading using a file. My objective is to load this data directly into the report, as shown in the code.
Attachments
data.json
(19.46 KiB) Downloaded 293 times
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: 2018.1.2 How to add JSON data?

Post by HighAley »

Hello.

Sorry, it's hard to say what is wrong with your project.
We need to see it and reproduce the issue on our side.

Thank you.
shadowkras
Posts: 27
Joined: Wed Jan 30, 2013 10:53 am
Location: Cuiabá/Mato Grosso - Brazil

Re: 2018.1.2 How to add JSON data?

Post by shadowkras »

Take a sample MVC project with Stimulsoft.Reports.Web.NetCore 2018.1.2 (some examples here), try to load the report data from a json string instead of loading a file, like the example I provided.

I will attach the json report Im loading the data to.

The report file loads, because those textboxes are from it's layout, but I get this error message when trying to use the RegData method. There are no exceptions, it simply doesnt load anything and shows this message.
stimulerror.jpg
stimulerror.jpg (47.92 KiB) Viewed 7414 times
Attachments
report..mrt
(11.36 KiB) Downloaded 238 times
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: 2018.1.2 How to add JSON data?

Post by HighAley »

Hello.

You could use next code to register your data.
The main issue is that you have a JSON connection n your report but registering a DataSet.
So you should remove them and synchronize the dictionary.

Code: Select all

DataSet data = Stimulsoft.Base.StiJsonToDataSetConverterV2.GetDataSetFromFile(StiNetCoreHelper.MapPath(this, "Reports/Data/Data.json"));
report.Dictionary.Databases.Clear();
report.Dictionary.DataSources.Clear();
report.RegData(data);
report.Dictionary.Synchronize();
Thank you.
shadowkras
Posts: 27
Joined: Wed Jan 30, 2013 10:53 am
Location: Cuiabá/Mato Grosso - Brazil

Re: 2018.1.2 How to add JSON data?

Post by shadowkras »

I actually replied on another topic earlier today by mistake.

Alright, I managed to get it to work by first parsing my JSON string to a jToken object, and then converting it to a dataset.
However, dataset objects are quite heavy and have many unnecessary properties.

Code: Select all

var ambienteJson = _ambienteRelatorio.ObterAmbienteRelatorioToJson(empresaId: 1);                
var ambienteToken = Stimulsoft.Base.Json.Linq.JToken.Parse(ambienteJson);
var ambienteDataSet = StiJsonToDataSetConverter.GetDataSet(ambienteToken);

StiReport.RegData("Ambiente", ambienteDataSet );
Another way I found was to load them as untyped objects, which saves them as Business Objects:

Code: Select all

var ambienteTypedObject = _ambienteRelatorio.ObterAmbienteRelatorio(empresaId: 1);
StiData ambienteStiData = new StiData("Ambiente", ambienteTypedObject);

StiReport.RegData("Ambiente", ambienteStiData);
But this makes them load with several unwanted properties (those marked in red are original from my object), as seen on this screenshot:
data_business_object.png
data_business_object.png (4.32 KiB) Viewed 7400 times
Is there any other way to load this json string directly into the report?

For the record, Im using Stimulsoft.Reports.Web.NetCore (v. 2018.1.3).
shadowkras
Posts: 27
Joined: Wed Jan 30, 2013 10:53 am
Location: Cuiabá/Mato Grosso - Brazil

Re: 2018.1.2 How to add JSON data?

Post by shadowkras »

Another (unsuccessful) attempt was using the StiReport.Dictionary.LoadFromJsonObject method:

Code: Select all

var ambienteJson = _ambienteRelatorio.ObterAmbienteRelatorioToJson(empresaId: 1);
var ambienteJsonObject = Stimulsoft.Base.Json.Linq.JObject.Parse(ambienteJson);

StiReport.Dictionary.LoadFromJsonObject(ambienteJsonObject);
StiReport.Dictionary.Synchronize();
But my data was nowhere to be seen.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: 2018.1.2 How to add JSON data?

Post by HighAley »

Hello.

We need to reproduce your issue on our side to help you.
Maybe we missed something.
Could you send us a sample project?

Thank you.
shadowkras
Posts: 27
Joined: Wed Jan 30, 2013 10:53 am
Location: Cuiabá/Mato Grosso - Brazil

Re: 2018.1.2 How to add JSON data?

Post by shadowkras »

The codes I provided should be enough to reproduce using one of the sample projects on github.
I did manage to get everything working with DataSets, but if there is a way to avoid using them and load the json string directly into the report, it would be great. Keep in mind that loading from a file is working, but not directly from a json string.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: 2018.1.2 How to add JSON data?

Post by HighAley »

Hello.

Yes, it's possible to load the JSON into the report.
You could add JSON as a Resource and use it as a Data Source.

Thank you.
Post Reply