Script objects can be a group of script functions that are used to implement a certain functionality or logic. They can be reused within the application. You can also pass parameters to a script function and get results accordingly.
Let us consider a scenario where you have four charts – Top 10 Super Commodities, Sectors, Entities and Spend Trend. On making selection on any of the first three charts, the selection should be filtered on the Spend Trend chart. Let us learn how script objects can be useful to achieve the functionality shown below.
Adding a Script Object and Script Function
1. A new script object can be added from the left panel using the plus icon.
2. By default, a script function ‘function1’ is created.
3. A pop up opens where you can configure the function.
4. Let us enter the name as ‘Func_Filter’. You can also appropriate description.
5. This function does not need to return any value. So, select Return Type as void.
Script Function Arguments
1. The script function should take two input arguments.
2. Add one argument of type Chart.
3. And another one of a type String array.
4. Once the arguments are added click Done.
Click on the function icon on the left side panel to open the Script Editor.
You can use the script function to copy filters from one chart to another where the name of the chart and dimension is passed as arguments. With the use of APIs copyDimensionFilter() you can replicate the filter conditions. Here the trend chart is filtered according to the filter values available in the main chart.
Calling Script Function
Once the script has been set for the script function, it can be executed /called from any widget. Here the script function needs to be called whenever the results of the chart widgets on the top have changed.
In the onResultChanged event of all the three chart components call the script function by passing two parameters – chart name and dimension name array. Func_Filter has two input arguments – GV_Chart and GV_Dimension – of type Chart and String array.
Add the script to other charts as well.
Now you can run the application and test the scenario.
Reach out to us here today if you are interested in evaluating if SAP Analytics Cloud is right for you.