Adding JavaScript to a report

Applies to version 11.0.4 and subsequent versions unless specifically overridden

Add JavaScript to a report to provide your own user interfaces when the report is run in HTML.

About this task

In IBM® Cognos® Analytics, you can add JavaScript in the following ways.

  • As with IBM Cognos Business Intelligence releases, you can add JavaScript in HTML item objects.

    In Cognos Analytics, JavaScript in HTML items is executed only when the report is run with limited interactivity (the report property Run with full interactivity is set to No).

    Note: If you run a report with full interactivity, use HTML items to insert only static HTML or static CSS into the report output.
  • You can add JavaScript to reports by using two types of Asynchronous Module Definition (AMD) modules.

    With this choice, JavaScript is executed when the report is run with full interactivity (the report property Run with full interactivity is set to Yes).

    The JavaScript must exist in a separate file that your browser can access.

The two types of AMD modules that you can use are

  1. A module that implements the CustomControl Module interface.
  2. A module that implements the Page Module interface.

You add a CustomControl Module interface to a report by referencing the interface in a custom control object. The reference is a file location that you specify in the Module path property of the custom control. Add a custom control to provide your own user interface for a prompt-like control that reads and sets parameters or for page navigation buttons.

You add a Page Module interface by referencing the interface in a report page or a prompt page. The reference is a file location that you specify in the Module path property of the page. Add a page module to set the initial state of prompt controls, to set prompt control custom validation functions, or to read current selections from a prompt control.

For information about the JavaScript that Cognos Analytics supports, see the technote Adding JavaScript to a report (www.ibm.com/support/docview.wss?uid=swg21990557) and article describing the list of JavaScript samples (https://community.ibm.com/community/user/businessanalytics/blogs/steven-macko/2018/03/22/updated-javascript-samples-for-ibm-cognos-analytics-11010?CommunityKey=6b10df83-0b3c-4f92-8b1f-1fd80d0e7e58&tab=recentcommunityblogsdashboard).

Procedure

  1. To add a custom control, from the toolbox toolbox icon, drag the Custom control icon custom control icon to the report.
  2. Select the custom control and click the Show properties icon Show properties icon.
    1. To specify the location of the file that contains the JavaScript that you want to use for the control, click the Module path property.
    2. To add JSON that configures the custom control, click the Configuration property.

      For example, add JSON that sets the orientation, alignment, and background color of the control.

    3. To specify how you want the control to interact with the report, click the UI type property.

      If you do not want to render an interface, set the property to None. If you do not want events, such as mouseup, to propagate from the control to the report, set the property to UI without event propagation. If you want events to propagate to the report, set the property to UI with event propagation.

  3. To add a page module interface, open the property sheet of the report page or prompt page, click the Module path property, and specify the location of the file that contains the JavaScript that you want to use.