Extending Master Data Maintenance Using Scripting

Objective

After completing this lesson, you will be able to Extend master data maintenance using scripting.

Master Data Maintenance

Using Built-in Functionality to Add Members to a Dimension

You can easily add members to dimensions using the built-in functionality in SAP Analytics Cloud planning stories. However, when creating new master data and adding the required properties, some planners aren't sure what attribute values to use. As a result, they have to spend time looking through other documentation to find the exact property name.

It is difficult to keep the data consistent, for example in a scenario where there are several planners forecasting product sales for new products with multiple properties.

For more information, visit SAP Help Create New Dimension Members Without Leaving Your Table

Scenario: Extend Master Data Maintenance with Scripting

Watch this video to learn more about the team's requirements for extending a story with scripting for easier and more consistent master data maintenance.

Business Scenario

The next 24 months will be very busy for the team. With many new products being launched, they have to create master data for each new product when they're planning. It's very time consuming and the results can be quite inconsistent.

You work with your colleague Laura to fully understand the business requirements for the master data creation for new products. You suggest creating a custom popup dialog where the IDs are system generated and a series of text boxes, dropdowns, and radio buttons prompt users for the required properties.

Story Setup

Before you write your script, you create the Create Article button and the Popup_Add popup. You add and configure the required widgets to meet the business requirements, making note of all of the ID names for your script.

Popup Settings

You plan to use custom buttons in the popup dialog. When you create the popup, you add four buttons:

  1. Save & Close: Saves the new member and closes the popup.
  2. Save & New: Saves the new member but keeps the popup open.
  3. Cancel: Closes the popup without saving.
  4. Clear All Attributes: Allows the planner to clear existing values after choosing Save & New.

Description

The Article_Desc text widget is configured so that planners can enter free text into the field.

Brand

The Article_Brand dropdown widget is configured so that planners can select from a list of valid values. You initially configure it so that it's set to Not assigned because you will add scripting to pull the values from the public dimension.

Leather

The Article_Leather radio button widget is configured so that planners can select between two options.

Clothing Method

The Article_Clothingmoment dropdown widget is configured so that planners select from the options created in the Builder panel.

Code Used in this Scenario

In the following examples, you can see the code used in the scenario and exercise to extend the planning story.

Update Dropdowns

When a planner opens the story, the dropdowns are updated from the latest dimensional data. Once this is complete, a ready message is displayed.

The following script is added to Page_1 on page initialization:

Code Snippet
Copy code
Switch to dark mode
1234567
var brand = ArticleAttributesModel.getMembers("UOOD_A_BRAND") for (var counter = 0; counter < brand.lenght; ++counter){ Article_Brand.addItem(brand[counter].id, brand[counter].id+ " – "+ brand [counter].description); } Application.showMesage(ApplicationMessageType.Success, "Application is loaded, you can create new Articles);

Open Popup

When the planner clicks the Create Article button in the story, a custom popup opens for the user, prompting them to select properties for the new article.

The following script is added to Button_Add:

Code Snippet
Copy code
Switch to dark mode
12
Popup_Add.open(); Article_ID.applyText(Utils.getID());

Generate Article ID

The IDs for existing articles are read using a script.

The following script is added to the getID script object:

Code Snippet
Copy code
Switch to dark mode
1
return "Art_"+PlanningModel.getMembers("Article").lenght.toString();

There are two models used in the planning story by the team. The ArticleAtributesModel contains the brand dimension and the PlanningModel contains the article dimension. Both models are referenced in the Planning Models node in the story.

New articles are added to the PlanningModel, which in the scenario is P00M_ProductSalesMD.

Additional Code and Script Variables Used in the Story

There are other configurations not covered in the exercise, but are provided below:

Popup Buttons

When you created the popup, you added four buttons in the popup settings.

  1. Save & Close
  2. Save & New
  3. Cancel
  4. Clear All Attributes

You created and added the following script to Popup_Add - onButtonClick:

Code Snippet
Copy code
Switch to dark mode
123456789101112131415161718192021222324252627282930313233
if (buttonId === "clear_all"){ Article_Desc.setValue(""); Article_Brand.setSelectedKey("#"); Article_Leather.setSelectedKey("No"); Article_Clothingmoment.setSelectedKey("#"); } else{ if (buttonId === "button_cncl") { this.close();} else { SV_Materialmember = ({id: Article_ID.getPlainText(), description: Article_Desc.getValue(), properties: { Brand: Article_Brand.getSelectedKey(), Clothing_Moment:Article_Clothingmoment.getSelectedKey(), Leather:Article_Leather.getSelectedKey() }}); var result = PlanningModel.createMembers("Article",SV_Materialmember); if(result) { Application.refreshData([Table_1.getDataSource(),]); Application.showMessage(ApplicationMessageType.Success,"Article Successfully Created"); if (buttonId === "button_okClose") { this.close(); } if (buttonId === "button_okNew") { Article_ID.applyText(Utils.getID()); } }}}

Script Variable

SV_Materialmember was added to the story. It is referenced in the Popup_Add script above and is used to read existing articles.

Brand Dropdown Widget

The Article_Brand dropdown widget will allow planners to select from a dropdown list of values.

In the Popup_Add - onButtonCilck, script is added that will pull the values from the public dimension. You can see the full script above, but the script below relates to the Brand dropdown values.

Brand: Article_Brand.getSelectedKey(),

Extend Master Data Maintenance using Scripting

Create Master Data Using a Custom Popup Dialog

What skills will you develop in this practice exercise?

In this practice exercise, you will:

  • Add script to the page that will run on initialization
  • Add script to the Create Article button to display the custom popup dialog
  • Add script to the popup widget to automatically create the ID
  • Create a new article using the popup in the story

View the Added Article in the Model

Once the new article has been created, you can view it in the model.

In the practice exercise, you created Dry Fit Shorts, which you can see in the example below in the Article dimension of the P00M_ProductSalesMD planning model.

Log in to track your progress & complete quizzes