Skip to Content

Introduction

Reading and displaying the value of Bex variable within WAD could be done with very simple way by using Info Field web item.

But what happens if you need to use this value within WAD (for example embed this value to any caption or just display it in other way that Info Field) ?

Goal

This blog describes how to read Bex variable value with JavaScript within WAD and embed it to tray caption of analysis item.

Business scenario

Let us consider a scenario where you have WAD application with analysis item based on Bex report that shows some amounts per customer and company code. If user has selected a particular customer, he wants to show this selected value within caption of analysis item’s tray.

General schema of implementation

We will follow the next steps in WAD:

1.     Add XML web item Data Provider – Information. This web item will generate XML with lot of useful information about the query such as variables and their values/texts, selections, query members and other information.

2.     Add Script web item that will parse XML data, find needed section (variables and their values), select variable value and concatenate it with a caption of analysis item’s tray.  Important note-it is preferable to base XML web item Data Provider – Information on different query than used for analysis item.

You can create simple query just with one info object restricted by some variable and without any key figure.

Such query will generate simple XML, will be fast and would not nestle performance of the WAD application.

Detailed implementation

I will create Bex query for XML web item.

This query will include just one info object (0CUSTOMER) restricted by variable ZCUST.

There are no key figures in this query.

VAR_JS_1.JPG

VAR_JS_2.JPG

When you will execute the WAD application, this query will generate XML file that you can view by right click on internet explorer page and selecting View Source.

I’ll bring only part (relevant for our topic) of generated XML:     

                                                                  

Then I’m going to create WAD page, add analysis item (set in his properties “With Tray” and add caption “Report for customer”), script item and XML web item.

VAR_JS_3.JPG

Data provider DP_1 is based on the query that shows data within analysis item Data provider DP_2 is based on the query that has been created especially for XML web item.

Finally I’ll add the next java script code to script web item:

This script will be executed during web page loading. The script will take the following actions:

1.     Parse XML tags

2.     Find VARIABLES node

3.     Find ZCUST variable value

4.     Concatenate ZCUST variable value with the string “Report for customer” (this is the caption of analysis item’s tray)

Finally, if I’ll select 1000102 for customer in variable selection screen, the caption of report will be changed dynamically, as shownbelow:

VAR_JS_4.JPG

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

  1. Christian Röttgers
    Awesome Code! Thansk for sharing. I am using the following code which works differently on IE and FireFox. Do you have an idea how this can happen?

    function ShowMatFilter()
    {
      root = document.childNodes[0];
      body = root.getElementsByTagName(“BODY”)[0];     
      xml  = body.getElementsByTagName(“XML”)[0];      
      bics = xml.childNodes[0];

    // in Explorer, the next command returns 10
    // in FireFox the next command return 0
    // how comes?
    alert(bics.childNodes.length);

    (0) 

Leave a Reply