Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
Showing results for 
Search instead for 
Did you mean: 
Former Member

SAP Design Studio 1.4 has a much needed feature that we were looking forward to – ‘Global Scripting’. Read on to find out what it is and how it has helped us, in a client scenario.

Creating Global Scripts

Global Scripting enables code reusability. Reusable scripts can be written in a ‘Global Scripts Object’. Each of these objects can have a number of script functions in them, which can be accessed using the object name – just like you would access the methods of a component. We can pass parameters to and get return values from these functions.

You can create a Global Scripts Object by right clicking on the ‘Technical Components’ folder in the Outline View, as shown.

Once the script function is created, you will be able to call the function from within other scripts in the application. The syntax is:


Our Business Scenario

As seen in the image above, we use KPI tiles in one of our dashboards for a client. KPIs such as Profit, Production Delay and Non-Defective Piece Count are calculated using scripts and displayed on the tiles.

To understand the duplication of code necessary without a global function, let me tell you what needs to be done here. In the OnApply() event of the dimension filter, we would have to get the measures from each data source, calculate the difference and set the value in the text box on the tile. This has to be repeated for every KPI tile. If there are additional dimension filters, then this whole set of code has to be written in each of the filters. What a huge overhead !

Here, comes the power of a global function that can just be written once and called as needed. This is just one typical business scenario – but using global scripts will make a big difference wherever a set of actions – like the above, or setting visibility, setting the css class etc – have to be repeated conditionally, across several components.

Please check out the code below for details of the implementation. This can be easily tweaked to accommodate change in data sources or addition of tiles.

The global scripts we defined were Difference_1 and SetText_1. Difference_1 calculates the difference between the appropriate values for the KPIs (for instance total sales – total cost for tile 1) and returns the value, in a string format.SetText_1 takes in a string and a text box alias and sets the text to the value taken in as parameter.

Shown below is the definition of ‘Difference_1’:

The second script, ‘SetText_1’ is much simpler as you can see:

Once we had the two scripts in place, we called the functions in the ‘onApply()’ event of the dimension filter:

//Defines the list of data sources

var DataSourceCollection = [DS_1,DS_2,DS_3];

//Defines the list of text components that need to be updated corresponding to each data source

var TextBoxCollection = [TEXT_KPI_1,TEXT_KPI_2,TEXT_KPI_3];

//Defines the list of first Measures for Difference

var FirstMeasureCollection = ["006EI4ZXZALE3K340F9IQKQ75","006EI4ZXZALE3K340F9IQK0WX","006EI4ZXZALE3K340F9IQKJVL"];

//Defines the list of Second Measures for Difference

var SecondMeasureCollection = ["006EI4ZXZALE3K340F9IQKDK1","006EI4ZXZALE3K340F9IQJO9T","006EI4ZXZALE3K340F9IQJULD"];

//Comparing array members to call the script using appropriate Data Source - Measures pair

  1. DataSourceCollection.forEach(function(ds_element, ds_index) {

TextBoxCollection.forEach(function(text_element, text_index) {

    if(text_index == ds_index)


      FirstMeasureCollection.forEach(function(FMC_element, FMC_index) {

            SecondMeasureCollection.forEach(function(SMC_element, SMC_index) {

                  if(SMC_index == FMC_index && FMC_index == text_index)


                        //Global Script Function Call

                        GLOBAL_SCRIPTS_1.SetText_1(text_element,GLOBAL_SCRIPTS_1.Difference_1(ds_element, FMC_element, SMC_element));







This works well, with the tiles updating themselves each time a different value is chosen in the filter.

Just as an additional note – we used arrays to define the different data sources, text boxes and measure pairs, for easier maintenance and scalability. If we had to add more KPI tiles that required the same functionality, we would just need to append:

  • Name of the Data Source used, to array “DataSourceCollection
  • Name of the Text Component to be updated, to array “TextBoxCollection
  • Name of the 1st Measure of the difference calculation, to array “FirstMeasureCalculation
  • Name of the 2nd Measure of the difference calculation, to array “SecondMeasureCalculation

Developers would only have to add the appropriate pairs as members to each of the above-mentioned arrays and they are good to go, without any change required in the script. Slight changes would be required when completely different queries are used as Data Sources.

So, in a nutshell, we wrote reusable functions to help achieve the same functionality with much fewer lines of code – which is the biggest advantage of global scripting. An extremely useful feature. Thank you, SAP!

(Major Edit on 11/28/2014: Script has been re-written for proper reusability)


Labels in this area