Passing Json strings to report version 2018.1

Stimulsoft Reports.WEB discussion
sorinav
Posts: 21
Joined: Mon Jul 31, 2017 5:13 pm

Passing Json strings to report version 2018.1

Post by sorinav »

I need to adapt my project code to the new version 2018.1 of Stimulsoft Reports

I am trying to load a json string to the report:

Code: Select all


report.Load(StiNetCoreHelper.MapPath(this, "~/Content/Reports/Invoice.mrt"));
string invoice_jsondata = JsonConvert.SerializeObject(_invoiceDto);

// _invoiceDto is an instance of a class which contain a  ICollection<InvoiceDetail> InvoiceDetails;
string invoice_jsondata = JsonConvert.SerializeObject(_invoiceDto);
string jsondata = Regex.Replace(invoice_jsondata, @"\t|\n|\r", "");

StiNetCoreViewer.GetReportResult(this, jsondata);



If I use this I am getting an error:

Column 'InvoiceDetails' doesnt not exist in Data Source 'root' and relation root cannot be created! It working if I have the json string in a file and load the report like that.

Can anyone tell me what I am doing wrong? Thanks a lot.
sorinav
Posts: 21
Joined: Mon Jul 31, 2017 5:13 pm

Re: Passing Json strings to report version 2018.1

Post by sorinav »

I also tried to use an object like this:

Code: Select all

public class InvoiceDto
    {

        //public int Id { get; set; } // ID (Primary key)
        public string OrderNumber { get; set; }
        public string CustomerID { get; set; } 
        public DateTime? DueDate { get; set; }
        public DateTime? OrderDate { get; set; }
        public string Type { get; set; }
        public string CustomerPO { get; set; }
        public string BillToCompany { get; set; }
        public string BillToAttention { get; set; }
        public string BillToSalutation { get; set; }
	....
	...
	...
	...

        public virtual ICollection<InvoiceDetailsDto> InvoiceDetails { get; set; }

    }

public class InvoiceDetailsDto
    {
        public int ID { get; set; }
        public string OrderNumber { get; set; }
        public string OriginalOrderNumber { get; set; }
        public string ProjectName { get; set; }
        public string ProductID { get; set; }
	...
 	...
	...
    }
Create the Business Object accordingly
but the report has no data in it

What am I doing wrong? Thank you!
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Passing Json strings to report version 2018.1

Post by HighAley »

Hello.

Sorry, we can't say what is wrong without seeing the whole picture.
Could you send us a sample project that will help us to reproduce the issue?

Thank you.
sorinav
Posts: 21
Joined: Mon Jul 31, 2017 5:13 pm

Re: Passing Json strings to report version 2018.1

Post by sorinav »

Hi,

Attached is a modified version of "Show Report in the Viewer" from the sample solution.

Thank you very much!
Attachments
Show Report in the Viewer.zip
(1.98 MiB) Downloaded 228 times
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Passing Json strings to report version 2018.1

Post by HighAley »

Hello.

You don't need to use RegData method. The JSON connection is already exists in the report with all Data Sources.
Only that you should do is change the path to the json file.

Code: Select all

(report.Dictionary.Databases[0] as Stimulsoft.Report.Dictionary.StiJsonDatabase).PathData = StiNetCoreHelper.MapPath(this, "Reports/Data/invoice.json");
Thank you.
sorinav
Posts: 21
Joined: Mon Jul 31, 2017 5:13 pm

Re: Passing Json strings to report version 2018.1

Post by sorinav »

Hi,

Maybe I was misunderstood but I am not interested in loading a json from a file,
I am interested in loading the report from an abject loaded from the database, exactly how I have done it before this release.
My entire project is based on this way to load the reports.

I really do not know how to ask this more clearly.
sorinav
Posts: 21
Joined: Mon Jul 31, 2017 5:13 pm

Re: Passing Json strings to report version 2018.1

Post by sorinav »

Aside from the sample project I sent to you here another example:

Consider this code:

Code: Select all

// this part right here simulates loadind the invoice data from the database 
using (StreamReader r = new StreamReader("Reports/Data/invoice.json"))
{
   invoice_jsondata = r.ReadToEnd();
   jsondata = Regex.Replace(invoice_jsondata, @"\t|\n|\r", "");
}

Stimulsoft.Base.Json.Linq.JObject jsonObj = Stimulsoft.Base.Json.Linq.JObject.Parse(jsondata);
(report.Dictionary.Databases[0] as Stimulsoft.Report.Dictionary.StiJsonDatabase).LoadFromJsonObject(jsonObj);
This is not working … the report is empty.
If this is not the right way, what is it then?

Thank you
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Passing Json strings to report version 2018.1

Post by HighAley »

Hello.

Sorry for the delay with answer.
During working on your issue we have found some bugs.
We need some time to make an improvement.

Thank you.
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Passing Json strings to report version 2018.1

Post by HighAley »

Hello.

The main issue is because you have a connection to a JSON file in your report template.
But you are registering a DataSet. So you should remove the connection.

Please, try to use this code:

Code: Select all

DataSet jsondata = Stimulsoft.Base.StiJsonToDataSetConverterV2.GetDataSetFromFile("Reports/Data/invoice.json");
report.Dictionary.Databases.Clear();
report.RegData("Invoice", jsondata);
report.Save(@"d:\Downloads\Show Report in the Viewer\Report.mrt");
Thank you.
shadowkras
Posts: 27
Joined: Wed Jan 30, 2013 10:53 am
Location: Cuiabá/Mato Grosso - Brazil

Re: Passing Json strings to report version 2018.1

Post by shadowkras »

I also have this same issue, I could load json directly into the report on 2017.2, but once I upgraded to 2018.1 this is no longer possible.

Loading from a local file works just fine, but saving a JSON string either as a dataset, jtoken or directly into a dictionary is not working.
Post Reply