Skip to main content

Introduction to the Business Intelligence JavaScript API

Introduction to the Business Intelligence JavaScript API

The Business Intelligence JavaScript API is provided by the file DeepSee.js, which is in the install-dir/CSP/broker directory. This JavaScript library enables you to interact with Business Intelligence from a client that is based on JavaScript. The functions in this library are a wrapper for a REST-based API for Business Intelligence. (You can also use the REST API directly.)

To use this library:

  1. Create a web application as described in the previous section.

    Or use the web application /api/deepsee, which is provided as part of the installation.

  2. In your JavaScript client code:

    1. Include the files DeepSee.js and zenCSLM.js.

    2. Create a Business Intelligence connection object. This contains information needed to connect to an InterSystems IRIS server.

    3. Create a Business Intelligence data controller object that uses the connection object.

      The data controller object enables you to interact with a Business Intelligence data source, which you specify either via an MDX query or via the name of a pivot table.

    4. Use the runQuery() method of the data controller. If the data source is an MDX query, Business Intelligence executes that query. If the data source is a pivot table, Business Intelligence executes the query defined by the pivot table.

    5. Invoke other methods of the data controller object to examine the query results, to drill down or drill through, and so on.

    The following subsections give the details.

The library DeepSee.js also provides utility functions that provide information about Business Intelligence model elements. Use these to obtain lists of available cubes, available measures in a cube, and so on.

Creating a Business Intelligence Connection

To create a Business Intelligence connection object, use code like the following:

connection = new DeepSeeConnection(username,password,host,application,namespace);

Where:

  • username is an InterSystems IRIS username that can access the given host.

  • password is the associated password.

  • host is the server name for the machine on which InterSystems IRIS is running.

  • application is the name of the web application.

  • namespace is the name of the namespace to access. If the web application is tied to a namespace, this argument is not needed.

Creating and Using a Business Intelligence Data Controller

The data controller object enables you to interact with Business Intelligence data sources. The primary interaction is as follows:

  • In a suitable part of the page logic (such as when the page is loaded or when a button is pressed), create a Business Intelligence data controller and execute a query.

    When you create a data controller, you specify one or two callback functions to be run when data is available; finalCallback is required, but pendingCallback is optional.

  • When pending results are available, Business Intelligence calls the method specified by pendingCallback, if specified.

    This method, which you write, uses the results that are available in the data controller object. The method typically draws page contents.

  • When the query has completed, Business Intelligence calls the method specified by finalCallback.

    This method, which you write, uses the results that are available in the data controller object. The method typically draws page contents.

Any method that executes a query uses the system described here; see the subsections for details and examples. Other methods return data synchronously.

Creating a Business Intelligence Data Controller and Executing a Query

In a suitable part of the client code (such as within the page initialization logic), do the following:

  1. Create a configuration object that has the following properties:

    • connection — Specifies the name of a Business Intelligence data connector object; see the previous section.

    • widget — Specifies the id of the HTML element on the page that will use the data controller

    • type — Specifies the type of data source; use either 'MDX' or 'PIVOT'

    • initialMDX — Specifies an MDX SELECT query; use this if type is 'MDX'

    • pivotName — Specifies the logical name of a pivot table; use this if type is 'PIVOT'

    • showTotals — Specifies whether to display totals. Specify either true or false

  2. Create a data controller object with code like the following:

    var dc = new DeepSeeDataController(configuration,finalCallback,pendingCallback);
    

    Where configuration is the configuration object from the previous step, finalCallback is the name of a callback function on this page, and pendingCallback is the name of another callback function on this page. finalCallback is required, but pendingCallback is optional.

  3. Call the runQuery() method of the data controller. Or run some other method that executes a query, such as runDrillDown() or runListing().

For example:

function initializePage() {
  ...
  configuration.connection = new DeepSeeConnection(username,password,host,application,namespace);
  dc = new DeepSeeDataController(configuration,drawChart);
  dc.runQuery();
}

Using Data Returned by the Data Controller

The page must also implement the callback function or functions referred to in the previous step. These callbacks should update the page as needed, using data obtained from the data controller object.

In each case, the data controller object is passed to the function as the argument.

The following shows a partial example:

function drawChart(dataController) {

  var resultSet = dataController.getCurrentData();
  ...
  var chartDataPoint;
  var chartLabel;
  var chartData = [];

  for (var i = 1; i <= resultSet.getRowCount(); ++i) {
   for (var j = 1; j <= resultSet.getColumnCount(); ++j) {
     chartDataPoint = resultSet.getOrdinalValue(i,j);
     chartLabel = resultSet.getOrdinalLabel(2,i);
     chartData[chartData.length] = { "country":chartLabel[0],"revenue":chartDataPoint};
    }
  }
  ...
}

The getCurrentData() method of the data controller returns another object, the result set object. That object provides methods for examining the results of the query. The example here shows some of them.

FeedbackOpens in a new tab