In the previous blog in this series, we learnt about Timer widget and export to PDF. In this blog, let us discuss various Script functions available for planning in Analytics Designer.

* * *

Analytic Application can be enhanced with planning Script functions to provide customized planning functionalities for various businesses. Here you can see a simple planning Script functionality of an Analytic Application in action below.

When you select a Profit Center, a popup is shown where you will be able to increase sales percent and change discount percent and expected cost. On applying changes, new Profit Forecast value is calculated, and the chart is refreshed accordingly. Let us see how to achieve this functionality within Analytics Designer in detail.


1. Table Widget as a Prerequisite

Like any other planning dashboard, you need a planning enabled model where you will be able to write back values. Here a planning model is used to create the chart that shows Profit Forecast per Profit Center. Since you need a table widget to write-back values, add a Table widget and include all necessary measures.

However, you don’t need to display the Table widget to the user. You can uncheck the option ‘Show this item at view time’ to hide the table from the user and fully leverage the planning Script functions to write-back values.


2. Adding Popup and Widgets

Once the Table and Chart are configured, you can add a popup containing widgets like Slider and Input Field for getting user inputs. A dropdown can be populated with the list of Profit Centers to allow the user to switch between them. A Slider widget can allow the user to change the increase in sales percentage within a range says 0 to 20. Another Slider widget can allow the user to change the discount percentage within a range say 0 to 35. The Input Field can be added so that users can change the expected cost (the Input Field can be prefilled with the current Cost Amount). To apply the changes and exit the popup, a button can be configured within the Builder panel.


3. Populating the Profit Center Dropdown

Since the members of the Profit Center dropdown within the popup needs to be populated only once, the following Script can be added in the onInitialization event.

Here in the Script, the list of profit centers is added to the dropdown using a for loop and then the Unassigned member is removed from the dropdown.


4. Opening the Popup for the selected Profit Center

The following Script can be added to the onSelect event of the Chart.

The profit center selection made by the user is saved in a local variable. In the case of multiple selections, only the first one in the list will be used. Then a for-in loop is used to find the selected profit center ID which is then passed as default selection to the dropdown within the popup. getData() function returns the raw value of the Cost Amount for the selected Profit Center which is then prefilled in the Input Field within the popup. Finally, the Script to open the popup is added.


5. Script Functions to write-back values

Within the popup, if the user switches between different Profit Centers, then the new Cost Amount should be prefilled in the Input Field. The following Script can be used in the onSelect event of the dropdown to dynamically prefill the Cost Amount.

Then on the onButtonClick event of the popup, the following Script can be added to write back new planned values.

Here in the Script,

  • getData() function is used to get the sales amount of the selected profit center
  • New Sales Amount is calculated by factoring in sales percentage
  • Discount Amount is calculated from sales using a discount percentage
  • Cost is obtained from the input field
  • Profit is calculated using sales, discount and cost amounts
  • getPlanning() function returns the planning object of the hidden Table widget
  • setUserInput() is used to enter the new planned values to the respective table cell with arguments – Selection and Value
  • submitData() function submits the newly entered user input to the planning module and recalculates any formulas
  • getPublicVersion() returns the ID of the public version for which the function publish() can be used to write back the values to the planning model

In the next blog in the series, we will discuss adding comments to an Analytic Application. Click here to evaluate if SAP Analytics Cloud is right for you. To know about the Analytic Applications of SAP Analytics Cloud, please check out our blog series here.

Subscribe to our Newsletter

5920 Windhaven Pkwy
Plano TX 75093.

+1 888-227-2794

+1 972-232-2233

+1 888-227-7192