Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

1.

IF ELSE
if (condition) {

// this block will be executed if condition is true

} else {

// this block will be executed if condition is false

2. SWITCH
var selectedCountry = Dropdown1.getSelectedText();

switch (selectedCountry) {

case "Germany":

// code that is relevant for Germany

break;

case "USA":

// code that is relevant for USA

break;

default:

// code that is relevant for all other countries

3. FOR--: to log all hierarchies from data source to console with FOR
var Hierarchies = TBL_Quantity.getDataSource().getHierarchies("0D_NW_PRID");

for (var j=0; j<Hierarchies.length; j++){

console.log(Hierarchies[j].id +" - " + Hierarchies[j].description);

}
4. WHILE--: to log all hierarchies from data source to console with WHILE
var Hierarchies = TBL_Quantity.getDataSource().getHierarchies("0D_NW_PRID");

var x = 0;

while (x < Hierarchies.length) {

console.log(Hierarchies[x].id +" - " + Hierarchies[x].description);

x++;

5. SHOW OR HIDE A WIDGET ON CLICK A KPI TILE

TILE 1 :

if (TS_Content.isVisible() === false) {

TS_Content.setVisible(true);

TS_Content.setSelectedKey("Tab_1");

TILE2 :

if (TS_Content.isVisible() === false) {

TS_Content.setVisible(true);

TS_Content.setSelectedKey("Tab_2");
6. ARRAY
Arrays are identified by [ ] as shown in the previous example above and can be:

- Printed to console

var resultset = Table_1.getDataSource().getResultSet();

console.log(resultset);

- Accessed with loop

var resultset = Table_1.getDataSource().getResultSet();

for (var x=0; x<resultset.length; x++){

console.log(resultset[x]["@MeasureDimension"].rawValue);

- Accessed with index

var resultset = Table_1.getDataSource().getResultSet();

console.log(resultset[1]);

- Scripting Situation Variable

Create empty array var myList = ArrayUtils.create(Type.string);

Create filled array var myList = ["Hello", "World", "Example"]

Add element myList.push("Hello world");

Remove last element myList.pop();

Read number of entries myList.length;

7. dynamically populate the dropdown:


var countries = Table_1.getDataSource().getMembers("0D_NW_BP__0D_NW_CNTRY");
for (var x = 0; x < countries.length; x++ ) {

var country = countries[x];

Dropdown_1.addItem(country.id, country.description);

8. return an array of all charts in your story with a name starting with "CH_Tile"

var tilecharts = Application.getWidgets({type:WidgetType.Chart, searchPattern:"CH_Tile"});

console.log (tilecharts);

9. to enhance an existing story with a dropdown to filter the Order Quantity table by
product category

var ProductABCratingList =
TBL_Quantity.getDataSource().getMembers("0D_NW_PRID__0D_NW_PRCAT");

for (var i=0; i<ProductABCratingList.length; i++){

if (ProductABCratingList[i].id !== ""){

DD_Product_ABC_rating.addItem(ProductABCratingList[i].displayId,
ProductABCratingList[i].description);

10. to the dropdown using the onSelect action:

TBL_Quantity.getDataSource().setDimensionFilter("0D_NW_PRID__0D_NW_PRCAT",
DD_Product_ABC_rating.getSelectedKey());

STEP 9 AND 10 IS FOR DYNAMIC DROPDOWN

You might also like