change only the XML data for a loaded .mrt report

Stimulsoft Reports.Flex discussion
Locked
brettcrossley
Posts: 6
Joined: Fri Dec 02, 2011 9:02 am
Location: Charlotte, NC

change only the XML data for a loaded .mrt report

Post by brettcrossley »

I want to programmatically load a MRT report, and replace the existing XML datasource used in the report w/ dynamic XML at run time.

I can do the following successfully:

Code: Select all

var xml: XMLNode = StiTypeConverter.byteArrayToXml(bytes);
var tempReport: StiReport = new StiReport();
tempReport.loadReportFromXML(xml);
tempReport.dictionary.databases[0].pathData="file:///Users/brett/html/season_box_score2.xml";
viewerFx.assignReport(tempReport);
but this of course requires me to build a temporary file.



Is there a way to load a report from XML, and then replace just the XML.
In the MRT created w/ the designer there is one DataConnection (XML) w/ Alias and Name="ReportConnection".
I tried this (which does not work):

Code: Select all

var tempReport: StiReport = new StiReport();
tempReport.loadReportFromXML(xml);
var dataXML:XML=getSomeXMLData();
tempReport.regDataXML("ReportConnection","ReportConnection",dataXML);
tempReport.dictionary.synchronize();
viewerFx.assignReport(tempReport);
Thank you for any advice.
brettcrossley
Posts: 6
Joined: Fri Dec 02, 2011 9:02 am
Location: Charlotte, NC

change only the XML data for a loaded .mrt report

Post by brettcrossley »

Figured it out, thought I would pass this along in case anyone else is doing the same thing.

If you are loading the data yourself you can just clear the existing database definition from the dictionary after you load your .mrt report:

Code: Select all

var tempReport: StiReport = new StiReport();
tempReport.loadReportFromXML(xml);
tempReport.dictionary.databases.clear();
The "database" in the dictionary is just the definition of the database, in this case pointing to the schema file and data xml, and setting an alias and name.

The alias and/or name are already set in the real data descriptor that binds to your report columns, etc. in the report, which is "dataSources"

The complete code to replace the XML dynamically is below:

Code: Select all

var tempReport: StiReport = new StiReport();
tempReport.loadReportFromXML(xml);
tempReport.dictionary.databases.clear();		
var dataXML:XMLNode=TestXml.getXml();                 // returns some XML
var schemaXML:XMLNode=TestXml.getSchema();      // returns some schema XML
tempReport.regDataXMLNode("ReportConnection","ReportConnection",dataXML, schemaXML);
tempReport.dictionary.synchronize();
viewerFx.assignReport(tempReport);
Vladimir
Posts: 1462
Joined: Fri Apr 13, 2007 4:05 am
Location: Earth

change only the XML data for a loaded .mrt report

Post by Vladimir »

Hello,

If you have already defined some database connection in the report, the data will be taken from him. In order to register other data, you must first clear all database connections:


var tempReport: StiReport = new StiReport();
tempReport.loadReportFromXML(xml);
var dataXML:XML=getSomeXMLData();
tempReport.dictionary.databases.clear();
tempReport.regDataXML("ReportConnection","ReportConnection",dataXML);
tempReport.dictionary.synchronize();
viewerFx.assignReport(tempReport);

Thank you.
Schadeck
Posts: 1
Joined: Thu Jul 28, 2016 2:11 pm

Re: change only the XML data for a loaded .mrt report

Post by Schadeck »

Estou com um problema parecido...

Trabalho com Delphi e tenho um formulário no módulo financeiro, que faz o gerenciamento dos documentos cadastrados e quando selecionado o documento, um botão para emissão de DANFE fica disponível. Preciso gerar o DANFE com base no documento que o usário selecionou no formulário, porém, é a partir de um XML que está salvo em um campo do banco de dado, no caso, quando o usuário seleciona o documento, seria necessário que a partir do formulário, fosse enviado o id (handle) do documento selecionado para o Stimulsoft, e de alguma maneira o Stimulsoft conseguisse buscar o XML do documento. Lembrando que, após encontrar o campo XML através do id (handle) passado pelo formulário, seria necessário transformar o XML em uma fonte de dados.

Atualmente, consigo utilizar qualquer XML como fonte de dados, mas o grande problema é que consigo utilizar somente definindo um caminho e nome padrão para o XML, no caso, seria necessário que o usuário colocasse no mesmo local e com o mesmo nome o arquivo XML e então gerasse um novo relatório.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: change only the XML data for a loaded .mrt report

Post by Alex K. »

Hello,

Sorry, maybe we did not exactly understand your question. Could you explain your issue in more details?

Thank you.
Locked