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.

Adding master data to a story using a new row in the table.

This topic is covered in the Adding New Dimension Members From Data Tables lesson in the Performing Manual Planning with SAP Analytics Cloud course.

Business 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.

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.

Custom pop up dialog created with scripting.

Story Setup

Before you add your scripts to extend the story, you create the BTN_Add 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.
Popup element with setting showing in the builder panel.

Description

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

Description text widget with setting showing in the builder panel.

Brand

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

Brand dropdown widget with setting showing in the builder panel.

Leather

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

Leather radio button widget with setting showing in the builder panel.

Clothing Moment

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

Clothing Method dropdown widget with setting showing in the builder panel.

Planning Models

The PlanningModel model contains the brand and the article dimensions. However, you could have a scenario, for example, where the brand is read from one model and articles created in another.

New articles that are created using the Create Article button are added to the PlanningModel, which in the scenario is Product_Sales_MD.

Planning Models.

Code Used in This Scenario

Now that the story is set up, it's time to add the code.

Update Dropdowns on Page Initialization

When a planner opens the story, the dropdowns in the popups need to be updated with the latest dimensional data. Once this is complete, a ready message is displayed.

To do this, the following script is added to Page_1 - onInitialization event:

Code Snippet
12345678
var brand = PlanningModel.getMembers("P00D_A_BRAND"); for (var counter = 0; counter < brand.length; ++counter){ if (brand[counter].description !== ""){ DD_Article_Brand.addItem(brand[counter].id, brand[counter].id+ " - "+ brand[counter].description); } } Application.showMessage(ApplicationMessageType.Success,"Story has loaded, you can create new Articles");
Page 1 and Code Used

Open Custom Popup

When the Create Article button in the story is selected, a custom popup opens. The planner is prompted to select properties for the new article.

To do this, add the following script to the BTN_Add - onClick event:

Code Snippet
12
POPUP_Add.open(); TXT_ID_Field.applyText(Utils.getID());
Button_Add and Code Used

Create Article

In the POPUP_Add the following script is added to the POPUP_Add - onButtonClick event:

Code Snippet
12345678910111213141516171819202122232425262728293031323334353637
if (buttonId === "clear_all"){ INF_Article_Desc.setValue(""); DD_Article_Brand.setSelectedKey("#"); RB_Article_Leather.setSelectedKey("No"); DD_Article_Clothingmoment.setSelectedKey("#"); } else{ if (buttonId === "button_cncl") { this.close(); } else { SV_Materialmember = ({ id: TXT_ID_Field.getPlainText(), description: INF_Article_Desc.getValue(), properties: { Brand: DD_Article_Brand.getSelectedKey(), Clothing_Moment:DD_Article_Clothingmoment.getSelectedKey(), Leather:RB_Article_Leather.getSelectedKey() } }); var result = PlanningModel.createMembers("Article",SV_Materialmember); if(result) { Application.refreshData([TBL_1.getDataSource(),]); Application.showMessage(ApplicationMessageType.Success,"Article Successfully Created"); if (buttonId === "button_okClose") { this.close(); } if (buttonId === "button_okNew") { TXT_ID_Field.applyText(Utils.getID()); } } } }
Script used for POPUP_Add.

Generate Article ID

A script reads the IDs for existing articles.

Add the following code to the Utils - getID script object:

Code Snippet
1
return "Art_"+PlanningModel.getMembers("Article").length.toString();
GetID and Code Used

Script Variable

The SV_Materialmember script variable is referenced in the POPUP_Add script above and is used to read existing articles.

Script Variable SV_Materialmember settings.

Extend Master Data Maintenance Using Scripting

Task Flow: 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.

Newly created article viewed in the Article dimension of the P00M_ProductSalesMD planning model.