JavaScript library callback functions

You can define a callback function when you instantiate Websheet and CubeViewer objects. The callback function traps changes to the title dimensions in the related object so you can process the event.

Websheet and CubeViewer objects both use the same format for defining a callback function. You add the callback function directly within the function that instantiates the TM1® Web object. Your code to handle the event goes inside this function.

Format

The callback function is defined with the following format:

onTitleDimensionElementChange: function(elementInfo) {

    // Add your code here to handle the title change event

    }

When a change to a title dimension is detected, the elementInfo object is passed to the callback function. The content of elementInfo is different for Websheet and CubeViewer objects. Use this information to see which dimension title has changed.

Websheet elementInfo object:
sheetIndex
Type: Integer
The zero-based index of the sheet that contains the SUBNM cell that was changed.
rowIndex
Type: Integer
The zero-based index of the row that contains the SUBNM cell that was changed.
columnIndex
Type: Integer
The zero-based index of the column that contains the SUBNM cell that was changed.
dimension
Type: String
The name of the dimension.
element
Type: String
The name of the element.
elementIndex
Type: Integer
The one-based index of the dimension element.
CubeViewer elementInfo object:
dimension
Type: String
The name of the dimension.
element
Type: String
The name of the element.
elementIndex
Type: Integer
The one-based index of the dimension element.

Websheet callback function example

The following example shows a callback function that is defined within the function that loads a Websheet object.

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.");
                },
                onTitleDimensionElementChange: function(elementInfo) {
                    console.debug("Title dimension element changed:");
                    console.debug(elementInfo);
                }            });
            
            dijit.byId("tabContainer").addChild(loadedWebsheet);
            
            loadedWebsheet.startup();
            
            unload.addOnUnload(function() {
                loadedWebsheet.destroy();
            });
        });
	};

CubeViewer callback function example

The following example shows a callback function that is defined within the function that loads a CubeViewer object.

function loadCubeview() {
	    require([
	        "tm1web/cubeview/CubeViewer",
	        "dojo/_base/unload"
	    ], function(CubeViewer, unload) {
            loadedCubeview = new CubeViewer({
                sessionToken: "yourSessionToken",
                cube: "plan_BudgetPlan",
                view: "Budget Input Detailed",
                isPublic: true,
                title: "Budget Input Detailed",
                onLoad: function() {
                    console.debug("CubeViewer loaded successfully.");
                },
                onTitleDimensionElementChange: function(elementInfo) {
                    console.debug("Title dimension element changed:");
                    console.debug(elementInfo);
                }            });
            
            dijit.byId("tabContainer").addChild(loadedCubeview);
            
            loadedCubeview.startup();
            
            unload.addOnUnload(function() {
                loadedCubeview.destroy();
            });
        });
	};