Show TOC

 JavaScript API for Executing CommandsLocate this document in the navigation structure

You can execute commands or command sequences using JavaScript.

To execute a command, you must first generate the command and its parameters. The command object sapbi_Command and the parameter object sapbi_Parameter are available for this purpose. In the script Web item, the command wizard provides help generating the JavaScript. Once you select the command and set the parameters, the JavaScript code is generated. 

Command Structure and Parameters

Parameter Object sapbi_Parameter

A parameter consists of a name and a value. To generate a new parameter in JavaScript, you use the following syntax:

  • var parameter_object = new sapbi_Parameter("Name", "Value");

Some parameters have child parameters (lists or nested parameters). For these parameters, you specify the child parameters in a parameter list (see parameter list below). To add parameter lists, you use the following method:

  • setChildList(parameter_list)

Parameter List sapbi_ParameterList

To instantiate a parameter list, you use the following syntax:

var parameter_list = new sapbi_Parameter();

You can add parameters to the list by using the following methods:

  • parameter_list.addParameterNameValue("Name","Value");
  • parameter_list.addParameter(parameter_object);

If you want to change a specific parameter that is already in the list, use the following syntax and specify the index (see example below):

  • paramList.setParameter(parameter_object, 1);

Command Object sapbi_Command

An sapbi_Command object is instantiated as follows:

  • var command = new sapbi_Command("Name of Command");

To add a parameter object to the command, you use the addParameter method. You can also use the addParameterNameValue command:

  • command.addParameterNameValue("Name","Value");
  • command.addParameter(parameter_object);

Command List sapbi_CommandSequence

An sapbi_CommandSequence is a list of sapbi_Commands.

The object is instantiated as follows:

  • var cmdSeq = new sapbi_CommandSequence();

The addCommand method is available to add commands to the command sequence.

  • cmdSeq.addCommand( sapbi_Command );

The command or command sequence is executed using the following method:

  • sapbi_page.sendCommand(CommandOrCommandSequenceObject)
Example

Example 1

In the command wizard, you have set the Swap Axes(SWAP_AXES) command for the data provider DP_1. The XHTML view in the Web Application Designer displays the following result (only the INSTRUCTION node is show in this example):

<bi:INSTRUCTION >

<bi:SWAP_AXES >

<bi:TARGET_DATA_PROVIDER_REF_LIST type="ORDEREDLIST" >

<bi:TARGET_DATA_PROVIDER_REF index="1" value="DP_1" />

</bi:TARGET_DATA_PROVIDER_REF_LIST>

</bi:SWAP_AXES>

</bi:INSTRUCTION>

This results in the following conversion in JavaScript:

/* Create TARGET_DATA_PROVIDER_REF */

var paramListDP_LIST = new sapbi_ParameterList();

var paramDP_LIST = new sapbi_Parameter( "TARGET_DATA_PROVIDER_REF_LIST", "" );

paramListDP_LIST.addParameterNameValue ("TARGET_DATA_PROVIDER_REF", "DP_1" );

paramDP_LIST.setChildList (paramListDP_LIST);

 

/* Create Command */

var commandSWAP_AXES = new sapbi_Command("SWAP_AXES");

commandSWAP_AXES.addParameter( paramDP_LIST );

 

/* Send Command */

sapbi_page.sendCommand(commandSWAP_AXES);

Example 2

To hide the ANALYSIS_ITEM_1 Web item, you have set the Set Web Item Parameters command (SET_ITEM_PARAMETERS) in the command wizard.

Note that when you set Web item parameters (SET_ITEM_PARAMETERS), the special rule for INIT_PARAMETERS applies. See also: Using Parameters to Call Web Applications

The XHTML view in the Web Application Designer displays the following result (only the INSTRUCTION node is show in this example):

<bi:INSTRUCTION >

<bi:SET_ITEM_PARAMETERS >

<bi:cmd_item_parameters type="ANALYSIS_ITEM" >

<bi:VISIBILITY value="VISIBLE" />

</bi:cmd_item_parameters>

<bi:TARGET_ITEM_REF value="ANALYSIS_ITEM_1" />

</bi:SET_ITEM_PARAMETERS>

</bi:INSTRUCTION>

 This results in the following conversion in JavaScript:

/* SET_ITEM_PARAMETERS */

 

/* Create TARGET_DATA_PROVIDER_REF */

var paramListINIT_PARAMETERS = new sapbi_ParameterList();

var paramINIT_PARAMETERS = new sapbi_Parameter( "INIT_PARAMETERS", "" );

paramListINIT_PARAMETERS.addParameterNameValue ("VISIBILITY", "VISIBLE" );

paramINIT_PARAMETERS.setChildList (paramListINIT_PARAMETERS);

 

var paramTARGET_ITEM_REF = new sapbi_Parameter( "TARGET_ITEM_REF", "ANALYSIS_ITEM_1" );

 

/* Create Command */

var commandSET_ITEM_PARAMETERS = new sapbi_Command("SET_ITEM_PARAMETERS");

commandSET_ITEM_PARAMETERS.addParameter( paramINIT_PARAMETERS );

commandSET_ITEM_PARAMETERS.addParameter( paramTARGET_ITEM_REF );

 

/* Send Command */

sapbi_page.sendCommand(commandSET_ITEM_PARAMETERS);

Example 3

You have set the Set Web Item Parameters(SET_ITEM_PARAMETERS) command in the command wizard to change the label of the first button in Web item BUTTON_GROUP_ITEM_1 to Text in JavaScript. This example illustrates how existing parameters in a list can be changed by using setParameter.

Note that when you set Web item parameters (SET_ITEM_PARAMETERS), the special rule for INIT_PARAMETERS applies. See also: Using Parameters to Call Web Applications

The XHTML view in the Web Application Designer displays the following result (only the INSTRUCTION node is show in this example):

<bi:INSTRUCTION >

 <bi:SET_ITEM_PARAMETERS >

 <bi:cmd_item_parameters type="BUTTON_GROUP_ITEM" >

 <bi:BUTTON_LIST type="ORDEREDLIST" >

 <bi:BUTTON type="COMPOSITE" index="1" >

 <bi:CAPTION value="Text in JavaScript" />

 </bi:BUTTON>

 </bi:BUTTON_LIST>

 </bi:cmd_item_parameters>

 <bi:TARGET_ITEM_REF value="BUTTON_GROUP_ITEM_1" />

 </bi:SET_ITEM_PARAMETERS>

</bi:INSTRUCTION>

This results in the following conversion in JavaScript:

/* Create Command */

var commandSET_ITEM_PARAMETERS = new sapbi_Command( "SET_ITEM_PARAMETERS" );

 

/* Create parameter ITEM_TYPE */

var paramITEM_TYPE = new sapbi_Parameter( "ITEM_TYPE", "BUTTON_GROUP_ITEM" );

commandSET_ITEM_PARAMETERS.addParameter( paramITEM_TYPE );

 

/* Create parameter INIT_PARAMETERS */

var paramINIT_PARAMETERS = new sapbi_Parameter( "INIT_PARAMETERS" );

var paramListINIT_PARAMETERS = new sapbi_ParameterList();

commandSET_ITEM_PARAMETERS.addParameter( paramINIT_PARAMETERS );

 

// Create parameter BUTTON_LIST

var paramBUTTON_LIST = new sapbi_Parameter( "BUTTON_LIST", "" );

var paramListBUTTON_LIST = new sapbi_ParameterList();

 

// Create parameter BUTTON

var paramBUTTON = new sapbi_Parameter( "BUTTON", "" );

var paramListBUTTON = new sapbi_ParameterList();

 

// Create parameter CAPTION

var paramCAPTION = new sapbi_Parameter( "CAPTION", "Text in JavaScript" );

paramListBUTTON.addParameter( paramCAPTION );

 

paramBUTTON.setChildList( paramListBUTTON );

paramListBUTTON_LIST.setParameter( paramBUTTON, 1 );

// End parameter BUTTON!

 

paramBUTTON_LIST.setChildList( paramListBUTTON_LIST );

paramListINIT_PARAMETERS.addParameter( paramBUTTON_LIST );

// End parameter BUTTON_LIST!

 

paramINIT_PARAMETERS.setChildList( paramListINIT_PARAMETERS );

 

/* Create parameter TARGET_ITEM_REF */

var paramTARGET_ITEM_REF = new sapbi_Parameter( "TARGET_ITEM_REF", "BUTTON_GROUP_ITEM_1" );

commandSET_ITEM_PARAMETERS.addParameter( paramTARGET_ITEM_REF );

 

/* Send Command */

sapbi_page.sendCommand(commandSET_ITEM_PARAMETERS);