Loading Websheet objects with the JavaScript library

Use a combination of JavaScript and Dojo to instantiate a Websheet object. After the object is loaded, you can then assign it as a child of a Dojo tab container or other container to display it in your web page.

You load a Websheet object by using the following format to specify the required properties and optional functions that define the object.

new Workbook({properties ..., functions ...});

The properties include values that specify the login credentials and the Websheet object that you want to open.

The functions can include optional code to notify you about onLoad and onTitleDimensionElementChange events for the object.

For more information, see Cognos TM1 Web JavaScript library Workbook class.

Example

The following example shows a JavaScript function that uses a combination of JavaScript and Dojo syntax to load a Websheet object.

The code to instantiate the object must use the specific Dojo syntax and the Dojo require keyword. After the object is loaded, the function assigns it as the child of a Dojo tab container object (dijit.layout.TabContainer).

// Load Websheet with parameters for adminHost, tm1Server, username and password
function loadWebsheet() {
    require([
        "tm1web/websheet/Workbook",
        "dojo/_base/unload",
    ], function(Workbook, unload){
        loadedWebsheet = new Workbook({
            adminHost: "localhost",
            tm1Server: "Planning Sample",
            username: "admin",
            password: "apple",
            path: "Applications/Planning Sample/Management Reporting/Actual v Budget",
            title: "Active v Budget",
            onLoad: function() {
                console.debug("Workbook loaded successfully.");
            },
        });

        // Assign object to a UI container
        dijit.byId("tabContainer").addChild(loadedWebsheet);

        loadedWebsheet.startup();

        unload.addOnUnload(function() {
            loadedWebsheet.destroy();
        });
    });
};

The following example loads a Websheet object by using a session token for the login.

// Load Websheet with a session token
function loadWebsheet() {
    require([
        "tm1web/websheet/Workbook",
        "dojo/_base/unload",
    ], function(Workbook, unload){
        loadedWebsheet = new Workbook({
            sessionToken: "yourSessionToken",
            path: "Applications/Planning Sample/Management Reporting/Actual v Budget",
            title: "Active v Budget",
            onLoad: function() {
                console.debug("Workbook loaded successfully.");
            },
        });

        // Assign object to a UI container
        dijit.byId("tabContainer").addChild(loadedWebsheet);

        loadedWebsheet.startup();

        unload.addOnUnload(function() {
            loadedWebsheet.destroy();
        });
    });
};