User Data in Reports

This example shows how to use the user data in the report and register it from code.

To use the XML data, first you should load XML file and convert it to the XML object. You can use the StiTypeConverter.stringToXml() static method for this purpose. After this action you can register XML data it the report using the regData() method of the report object. As parameters, you should pass the data source name and alias, and this XML object:

private var reportString: String;
private var xmlData: XMLNode;

private function onInitialize(): void

// Load XML data file
var request2: URLRequest = new URLRequest("reports/data/Demo.xml");
var loader2: URLLoader = new URLLoader();
loader2.addEventListener(Event.COMPLETE, onXmlLoadComplete);

private function onXmlLoadComplete(event: Event): void
var loader: URLLoader = as URLLoader;
var data: String = as String;

xmlData = StiTypeConverter.stringToXml(data);

private function onRegDataXmlClick(): void
// Create new report object
var report: StiReport = new StiReport();
// Load report from XML string
// Registration of XML data with same name "Demo"
report.regData("Demo", "Demo", xmlData);
// Show report in Viewer dialog window

Also you can use the DataSet, DataTable, DataColumn classes to create the user data set. For example create a Customers data table with one CustomerName data column and three data rows. After creation you can use the regData() method of the report object:

private function onRegDataSetClick(): void
// Create new Data Table
var table: DataTable = new DataTable("Customers");
// Create new Data Column
var column: DataColumn = new DataColumn("CustomerName", StorageType.StringType);
// Add Data Column to Data Table

// Create new Data Rows
table.addNewRow().setValue("CustomerName", "John Smith");
table.addNewRow().setValue("CustomerName", "Antonio Moreno");
table.addNewRow().setValue("CustomerName", "Elizabeth Brown");

// Create new Data Set
var dataSet: DataSet = new DataSet("DataSetName");
// Add Data Table to Data Set

// Create new report object
var report: StiReport = new StiReport();
// Registration of user Data Set
report.regData("DataSetName", "DataSetName", dataSet);
// Synchronize report dictionary
// Design report in Designer dialog window

In the screenshot below you can see the result of the sample code.

User Data in Reports