Skip to main content

Using Business Intelligence

This page introduces the JavaScript and REST APIs for InterSystems IRIS® data platform Business Intelligence. These APIs let you execute MDX queries and retrieve information about Business Intelligence model elements.

Creating a Web Application

In any scenario (whether you use the JavaScript API or you use the REST services directly), a web application is responsible for handling the requests. You can use the system-defined web application (/api/deepsee) or you can create and use a different web application. The requirements for this web application are as follows:

  • You must place your client file or files within the directory structure served by this web application.

  • You must specify the Dispatch Class option, which specifies how this web application handles REST requests. For Business Intelligence REST requests, use one of the following:

    • %Api.DeepSeeOpens in a new tab — Use this class if your client application must be able to connect to different namespaces. In this case, when you connect to an InterSystems IRIS server, you must specify the namespace to use.

      The system-defined web application (/api/deepsee) uses this dispatch class.

    • %DeepSee.REST.v3 — Use this class if the REST requests should be tied to a specific namespace (the namespace for the web application).

    The classes %DeepSee.REST.v2Opens in a new tab and %DeepSee.REST.v1Opens in a new tab are also available for use, but are documented only within the class reference.

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.

Introduction to the Business Intelligence REST API

Internally, the JavaScript API uses the Business Intelligence REST API, which you can also use directly, as follows:

  1. Create a web application.

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

  2. In your JavaScript client code, create and send HTTP requests to the desired target REST services.

    If you are using the dispatch class %Api.DeepSeeOpens in a new tab, use a target URL of the following form:

    https://baseURL/api/deepsee/v3/namespace/RESTcallname
    

    where baseURL refers to your instance, namespace is the target namespace, and RESTcallname is the actual rest call (for example, /Info/Cubes). For example:

    /mycompany/api/deepsee/v3/myapplication/Info/Cubes
    

    If you are using the dispatch class %DeepSee.REST.v3, use a target URL of the following form:

    /baseURL/api/deepsee/v3/RESTcallname
    

    For example:

    /mycompany/api/deepsee/v3/Info/Cubes
    
    Note:

    The client must accept JSON. The Accept header of the request must either specify application/json or not declare a format.

  3. Examine the response objects and use as applicable.

Use of Slashes in Cube and KPI Names

It is relatively common to use slashes (/) in the logical names of cubes and other items, because the slash character is the token that separates a folder name from a short item name. For example, a cube might have the logical name RelatedCubes/Patients

You can directly use these logical names unmodified in URL parameters (as well as in the request bodies). The applicable Business Intelligence REST services account for logical names that include slashes. The logic, however, requires you to follow a naming convention (depending on which REST services you plan to use). Specifically, do not have an item with a logical name that is the same as the name of a folder used by another logical name. For example, if you have an item called mycubes/test/test1, you should not have an item called mycubes/test.

The reason for this restriction is that when you use a REST service that uses another argument after the logical name, part of the name is interpreted as another argument if the first part of the name matches an existing item. Consider the following REST call:

https://localhost/api/deepsee/v3/Info/FilterMembers/:mycubename/:filterspec

Here mycubename is the logical name of a cube and filterspec is the specification for a filter provided by that cube. Now consider this REST call with mycubes/test/test1 as the name of the cube:

https://localhost/api/deepsee/v3/Info/FilterMembers/:mycubes/test/test1/:filterspec

In order to interpret the slash characters, the system first attempts to find a cube named mycubes and then attempts to find a cube named mycubes/test, and so on. When the system finds the first item that matches the apparent name, the REST call uses that item, and the remainder of the string is interpreted as the next argument.

Notes on the Response Objects

For most of the REST calls, the response objects contain the property Info, which contains information about the request and response. This object contains the property Error, which equals one of the following:

  • Null — This indicates that no error occurred.

  • An object that contains the properties ErrorCode and ErrorMessage — This object contains details about the error that you can use to determine whether and how to proceed.

If no error occurred, the response object also contains the property Result, which is an object containing the requested values.

In general, your client code should first check the Info.Error property and then determine how to proceed.

For example, a response object might look like this (with white space added for readability):

{"Info":
    {"Error":
        {"ErrorCode":"5001",
         "ErrorMessage":"ERROR #5001: Cannot find Subject Area: 'SampleCube'"}
    }
}

In contrast, if no error occurred, the Info.Error property is null and the Result contains the result that you requested. For example:

{"Info":
    {"Error":"",
    "BaseCube":"DemoMDX",
    "SkipCalculated":0},
    "Result":
        {"Measures":
            [
               {"name":"%COUNT","caption":"%COUNT","type":"integer","hidden":0,"factName":""},
               {"name":"Age","caption":"Age","type":"integer","hidden":0,"factName":"MxAge"}
        ...]
    }
}
FeedbackOpens in a new tab