Parent Detail Report - create relation in code

Stimulsoft Reports.JS discussion
Post Reply
mbaker78
Posts: 8
Joined: Fri Sep 13, 2019 5:03 am

Parent Detail Report - create relation in code

Post by mbaker78 »

Hi,
I have a report that uses a parent-detail relationship between two databands, which works fine when I set up the datasource and relationship in the actual .mrt file, but when I try to do it via javascript it doesn't work.

I get the data from a back-end database and return it as JSON.
All the data in the report loads but the detail part is showing all records for each master heading rather than just the specific headings. When I try to add a data Relation it errors so I haven't got the code right.

Here is my code:
var test = JSON.stringify(this.state.data);

var dataSet = new Stimulsoft.System.Data.DataSet("test");
dataSet.readJson(test)
report.regData(dataSet.dataSetName, "", dataSet);
report.dictionary.connect(false);
report.dictionary.synchronize();

var parentId: string[] = [];
parentId.push("id");
var childId: string[] = []
childId.push("headerId")

var dataRelation = new Stimulsoft.System.Data.DataRelation("Relation", report.dictionary.dataSources["scopeOfWorks"], report.dictionary.dataSources["scopeOfWorks_scope"], parentId, childId);
report.dictionary.regRelation(dataRelation.relationName, "", dataRelation);

viewer.report = report;
viewer.renderHtml('viewer');

Attached: A sample of Json that is similar to what I am returning from the database, and the actual .mrt file I am using
Attachments
Test Report.mrt
(65.1 KiB) Downloaded 186 times
json testing for report.json
(1.09 KiB) Downloaded 156 times
Lech Kulikowski
Posts: 6245
Joined: Tue Mar 20, 2018 5:34 am

Re: Parent Detail Report - create relation in code

Post by Lech Kulikowski »

Hello,

Please check that after regData() method tables names are the same as in your regRelation() method.
You can call the designer and check it.

Thank you.
mbaker78
Posts: 8
Joined: Fri Sep 13, 2019 5:03 am

Re: Parent Detail Report - create relation in code

Post by mbaker78 »

Thanks, I managed to get it working, didn't have quite the right syntax. Updated the relation code to:
var dataRelation = new Stimulsoft.Report.Dictionary.StiDataRelation("Relation", "Relation", "Relation", report.dictionary.dataSources.getByName("root_scopeOfWorks"), report.dictionary.dataSources.getByName("root_scopeOfWorks_scope"), ["id"], ["headerId"]);

report.dictionary.relations.add(dataRelation);

report.dictionary.synchronize();
Lech Kulikowski
Posts: 6245
Joined: Tue Mar 20, 2018 5:34 am

Re: Parent Detail Report - create relation in code

Post by Lech Kulikowski »

Hello

We are always glad to help you!
Please let us know if you need any additional help.

Thank you.
Post Reply