Start of Content Area

Background documentation Use of JavaScript in Web Applications and Web Items  Locate the document in its SAP Library structure

Using JavaScript in Web Applications

JavaScript can be incorporated in Web applications in two ways:

      Using a JavaScript include from the MIME Repository

Load the JavaScript include file to the MIME Repository of the BI system. To do this, on the SAP Easy Access screen, choose Business Explorer MIME Repository. You can store customer-specific scripts in the MIME Repository under SAP BW Customer JavaScripts.

You can reference the JavaScript include file as follows in the XHTML view for the Web template:

<script src="bwmimerep:///sap/bw/mime/Customer/Javascripts/myscript.js” type="text/javascript"></script>

      By incorporating JavaScript in a Web template using the Script Web item

In the Web Application Designer, drag the Script Web item from the Miscellaneous Web item grouping to your Web template and choose the Web Item Parameterstab page in the Properties area. Choose the editing dialog box for the parameter Script. You can insert your JavaScript in this dialog box. The command wizard helps you to generate the JavaScript code for executing the command.

Note

Due to the XHTML format, you cannot directly write JavaScript in the Web template. For this reason, the actual script is stored as a reference. The script can only be changed using the editing dialog.

If required, you can execute JavaScript in the Web browser after loading the Web application. Switch to the XHTML view in the Web Application Designer and call the JavaScript function in the onload event handler of the body tag.

<body onload=“javascript:<FUNCTION>();“>

<FUNCTION> is a placeholder for the function name.

If you want to call commands from the Web Design API, you can also use the standard actions for the Web template:

       Action Before Rendering (ACTION_BEFORE_RENDERING)

       Action Before First Rendering (ACTION_BEFORE_FIRST_RENDERING)

For more information, see Web Template Parameters.

You can access the following JavaScript function in the JavaScript:

sapbi_page.GetMainTemplateName();

Technical name of the Web template

Note

All other JavaScript variables and functions are for internal use only and are not intended to be used in Web applications.

Using JavaScript in Web Items

In addition to the direct use of commands using the command wizard, some Web items also provide the option of using JavaScript functions. This can be useful, for example, if you want to assemble commands dynamically, or if you use portal eventing and want to link this action to a Web item.

JavaScript functions linked to a Web item always have the same signature:

      function functionname(currentState, defaultCommandSequence)

The parameters currentState and defaultCommandSequence are used for Web items that already execute standard commands themselves. This applies, for example, to the data binding type CHARACTERISTIC_SELECTION for the Web item Dropdown Box. The command for setting the filter values is generally run here. You can insert this standard command sequence before or after your command, or you can choose to ignore it and not execute the standard command.

For an example of how to use JavaScript in a Web item, see Using JavaScript in the Dropdown Box Web Item.

 

End of Content Area