Embedded Reports API
The Embedded Reports API provides developers with easy and agile methods for embedding Logi report components into other, non-Logi web pages. This topic provides the following information about the API:
- Include the API
- Embed Static Reports using Markup
- Embed Dynamic Reports using Javascript
- Access Embedded Reports on Different Domains
- Prevent Session Timeout
Note that the Windows version of the Safari browser does not currently work with the Embed API.
Include the API
The Embedded Reports API, which is a Javascript file, is:
<yourLogiApp>/rdTemplate/rdEmbedApi/rdEmbed.js
To use it, include a link to it at the end of your custom HTML page, just above the </body> tag:
- <body>
- ...
- <script src="http://<yourLogiApp>/rdTemplate/rdEmbedApi/rdEmbed.js" type="text/Javascript">
- </script>
- </body>
Next, create a div element to contain the embedded Logi report, and give it a unique id attribute.
- <div id="div1" />
Then decide which of the two following embedding approaches, described in the following sections, you want to use: Markup or Javascript.
Note: The Embedded Reports API works well with all modern browsers, but some features (such as auto-sizing and accessing embedded reports) will not work with older browser, such as IE6 and IE7.
Embed Static Reports Using Markup
Static embedding allows you to embed a Logi report simply by manipulating the markup tags. This is done by adding the appropriate data-* attributes to the div container you've already created:
- <div id="div1" data-applicationUrl="yourLogiAppURL" data-report="yourReportName" data-autoSizing="all"></div>
The attributes are:
Attribute | Description |
---|---|
data-applicationUrl | Required The URL of your Logi Info application. |
data-report | Required The Logi report definition name. |
data-autoSizing | Required Specifies automatic resizing of the container div to show the entire report or include scroll bars. Valid values include: |
data-linkParams | A name-value collection of report parameters. |
data-secureKey | A SecureKey value; required when using SecureKey Authentication. |
Example 1: Simple Static Embedded Report
- <div id="div1" data-applicationUrl="http://sampleapps.logianalytics.com/logiapp" data-report="EmbeddedReports.DataTable" data-autoSizing="all"></div>
Example 2: Static Embedded Report with Parameters for use in Query
Style can also be added to the div to give it a border and background color.
- <div id="div2" data-applicationUrl="http://sampleapps.logianalytics.com/logiapp" data-report="EmbeddedReports.DataTable data-autoSizing="all" data-linkParams="{'CustomerID' : 'VINET', 'StartDate' : '01/01/1996'}" class="divFrame" ></div>
Example 3: Using a Fixed-Size Layout
By default, embedded reports fill 100% of their div container. To control the report size, you can specify the div element's size with width and/or height style attributes. If the embedded report's physical size is greater than its div container, the report will automatically show scrollbars. You can hide the scrollbars by using style for the div element: overflow(-x | -y): none;.
- <div id="div3" style="width:350px; height:150px;" data-applicationUrl="http://sampleapps.logianalytics.com/logiapp" data-report="EmbeddedReports.DataTable" data-linkParams="{'CustomerID' : 'CHOPS'}" ></div>
When you specify a size in this way, you can skip the normally required data-autoSizing attribute.
Embed Dynamic Reports using Javascript
You can also use Javascript and the EmbeddedReporting object from the API to embed reports. This object has three primary methods: create, get, and remove. Remember that Javascript is case-sensitive!
All three methods operate with the following properties:
Property | Type | Description |
---|---|---|
applicationUrl | string | Required The URL of your Logi Info application. |
report | string | Required The Logi report definition name. |
autoSizing | Required Specifies automatic resizing of the container div to show the entire report or include scroll bars. Valid values include: | |
linkParams | array | A name-value collection of report parameters. |
secureKey | string | A SecureKey value; required when using SecureKey Authentication. |
iframeId | string | Read Only Returns the id attribute value of the iframe element that contains the embedded report. |
iframe | object | Read Only Returns the iframe DOM object that contains the embedded report page |
Use the create() and remove() Methods
1. Create a container for the report in the HTML markup:
- <div id="reportContainer" />
2. In your Javascript code, create array of report options:
- var options = {};
- options.applicationUrl = "http://sampleapps.logianalytics.com/LogiApp";
- options.report = "EmbeddedReports.DataTable";
- options.autoSizing = "all";
- options.secureKey = "";
- options.linkParams = {"CustomerID" : "VINET", "StartDate" : "01/01/2009" };
3. Create a report instance:
- var report = EmbeddedReporting.create('reportContainer', options);
4. Remove the report instance:
- EmbeddedReporting.remove('reportContainer');
Try it:
Here's the Javascript used in this page, with the onClick events for the two buttons, to create and remove the report:
- function CreateReport() {
- var options = {
- applicationUrl : "http://sampleapps.logianalytics.com/LogiApp",
- report : "EmbeddedReports.DataTable",
- autoSizing : "all",
- linkParams : { "CustomerID": "VINET", "StartDate": "01/01/1976" }
- };
- var report = EmbeddedReporting.create('reportContainer', options);
- }
- function RemoveReport() {
- EmbeddedReporting.remove('reportContainer');
- }
Use the get() Method
To manipulate existing reports created with the API, start by getting the report object, using its container div ID:
- var report = EmbeddedReporting.get('containerId')
Report object properties can be directly manipulated:
- EmbeddedReporting.get('containerId').report = "SalesByMonth"
The report object also has these methods available:
Method | Description |
---|---|
loadReport() | Loads or refreshes an embedded report. |
setParam(name, value) | Updates or inserts a parameter into the report parameters collection. |
getParam(name) | Returns a parameter value from the report parameters collection. |
removeParam(name) | Removes a parameter from the report parameters collection. |
removeAllParams() | Removes all parameters from the report parameters collection. |
Usage examples follow below.
Example 1: Update Report Parameters
1. Create an embedded report using HTML markup:
- <div id="div5" class="divFrame" data-applicationUrl="http://sampleapps.logianalytics.com/logiapp" data-report="EmbeddedReports.DataTable" data-autoSizing="all"></div>
2. Add controls to the HTML page, then set onClick event to call this Javascript function:
- function UpdateReportParameters() {
- var reportObj = EmbeddedReporting.get("div5");
- var lst = document.getElementById('customerId');
- var customer = lst.options[lst.selectedIndex].value;
- reportObj.setParam("CustomerID", customer);
- reportObj.loadReport();
- }
Try it:
Customer: ANATR
BERGS
CHOPS
GREAL
Example 2: Select Different Reports
1. Create an embedded report using HTML markup:
- <div id="div6" data-applicationUrl="http://sampleapps.logianalytics.com/logiapp" data-report="EmbeddedReports.DataTable" data-autoSizing="height" ></div>
2. Add controls to the HTML page, then set onClick event to call this Javascript function:
- function ChangeReport() {
- var reportObj = EmbeddedReporting.get("div6");
- var lst = document.getElementById('lstReports');
- var reportName = lst.options[lst.selectedIndex].value;
- reportObj.report = reportName;
- reportObj.loadReport();
- }
Try it:
Available reports: EmbeddedReports.DataTable
EmbeddedReports.Chart
EmbeddedReports.AnalysisGrid
Access Embedded Reports on Different Domains
When an embedded report is hosted on a server in a different domain, you can't directly access a its DOM elements and Javascript functions due to iFrame cross-domain access policy restrictions. However, the EmbeddedReporting object provides functionality to get around those restrictions, using these methods:
execEmbeddedFunction(functionName, arg1, arg2, ...argN, callback)
Executes a Javascript function in an embedded report and returns its execution result.
Our example Logi app contains a report definition named EmbeddedReports.Elements and it includes this Javascript function:
- function SayHello(firstName, secondName) {
- var hello = "Hi " + firstName + " " + secondName + "!"
- return hello;
- }
We can use the execEmbeddedFunction method to remotely execute this function and then we can display its results locally.
1. Embed the report using HTML markup:
- <div id="div7" class="divFrame" data-applicationUrl="http://sampleapps.logianalytics.com/logiapp" data-report="EmbeddedReports.Elements" data-autoSizing="height"></div>
and here's the report:
2. Enter values for arg1 and arg2 on the current HTML page to send to the report's function, and click Execute:
Here's the supporting Javascript included in the current HTML page and called when you click Execute:
- function runEmbeddedFunction() {
- var funcName = document.getElementById('inpExecuteThis').value;
- var args1 = document.getElementById('inpArg1').value;
- var args2 = document.getElementById('inpArg2').value;
- var callback = document.getElementById('inpCallbackTo').value;
- var report = EmbeddedReporting.get('div7');
- report.execEmbeddedFunction(funcName, args1, args2, callback);
- }
- function showResults(result) {
- alert(JSON.stringify(result, null, 2));
- }
getElementAttribute(selector, attributeName, callback)
Returns an object with two properties: elements and values. The elements property contains a list of elements, which matched the search query. The values property contains a list of attribute values. The selector argument should represent a valid CSS ID selector string.
1. Embed the report using HTML markup:
- <div id="div8" class="divFrame" data-applicationUrl="http://sampleapps.logianalytics.com/logiapp" data-report="EmbeddedReports.Elements" data-autoSizing="all" ></div>
and here's the report:
2. Enter a CSS selector (#elementID) to specify the element, and an attribute name, and click Execute.
Here's the supporting Javascript included in the current HTML page and called when you click Execute:
- function GetElementAttribute() {
- var elementSelector = document.getElementById('inpSelector').value;
- var attrName = document.getElementById('inpAttrName').value;
- var callback = document.getElementById('inpCallbackTo').value;
- var report = EmbeddedReporting.get('div8');
- report.getElementAttribute(elementSelector, attrName, callback);
- }
- function showResults(result) {
- alert(JSON.stringify(result, null, 2));
- }
Note that values for Input Text Area and Input Select List elements cannot be retrieved using this method; you must write a separate function to extract their values and call it with execEmbeddedFunction() instead.
setElementAttribute(selector, attributeName, attributeValue, callback)
Sets an attribute value of element inside an embedded report. Returns
"true" when the element was found and an attribute has been updated
successfully. The selector
argument should represent a valid CSS selector string.
1. We'll use the report we embedded in the previous example.
2. Enter a CSS selector (#elementID), an attribute name and value, and click Execute. Scroll up to see the result.
Selector: Attribute name: Attribute value: Callback To:Here's the supporting Javascript included in the current HTML page and called when you click Execute:
- function SetElementAttribute() {
- var elementSelector = document.getElementById('inpSelector').value;
- var attrName = document.getElementById('inpAttrName').value;
- var attrValue = document.getElementById('inpAttrValue').value;
- var callback = document.getElementById('inpCallbackTo').value;
- var report = EmbeddedReporting.get('div8');
- report.setElementAttribute(elementSelector, attrName, attrValue, callback);
- }
- function showResults(result) {
- alert(JSON.stringify(result, null, 2));
- }
Note that, if the specified attribute does not exist, this method will create it and then set its value. Values for Input Text Area and Input Select List elements cannot be set using this method; you must write a separate function to set their values and call it with execEmbeddedFunction() instead.
Prevent Session Timeout
The parent application and its embedded Logi reports may be hosted on separate web servers and, if so, there will be independent session state maintained for them on each host. Session expiration on either host may cause problems. The Embed API provides functionality for preventing session timeout for parent and embedded reports. To use it, create a simple web page in the parent application, without any visual elements, and use the following method to "ping" it at specified intervals.
keepSessionsAlive(pingPageUrl, interval)
Pings parent and Logi servers at the defined interval (in milliseconds). Default interval is 60000 (1 minute).
- EmbeddedReporting.keepSessionsAlive("http://myParentApplication/pingMe.aspx", interval)
This function automatically determines the URL of the embedded Logi reports and pings a standard page that's supplied with the Logi Info product, so you don't have to create a page to ping in the Logi application. Note that this technique only works with a single Logi application; if you have reports from multiple Logi applications embedded in the same parent application, this method will not ping all the Logi applications.