After completing this lesson, you will be able to:
After completing this lesson, you will be able to:
Extend comment features with scripting
Comments
Using Built-in Functionality to Add Comments
You can easily add comments in planning stories using the built-in functionality in SAP Analytics Cloud.
Comments can be added to:
A cell in a data table using the built-in Add Data Point Comment option. If a cell already has comments, an indicator is displayed in the cell. Planners can view the comment by selecting the data cell.
A separate column(s) in a data table. Only the latest comment is displayed in the comment column.
Viewing and finding relevant comments can be time consuming if comments are used extensively as you have to scroll to the end of the story to the comment column or click on each cell to view the comments.
Scenario: Extend Comment Features with Scripting
Watch this video to learn more about the team's requirements for extending comment features in a story with scripting allow for easier viewing and creation of comments.
Business Scenario
The team values effective communication and collaboration and knows how critical it is for successful planning. They regularly document their planning assumptions as they work on forecasts. While they use both the comments column and data point comments, they wish it was easier to view, add, and delete comments. They also present their forecasts regularly to other teams in the company and have often forgotten to hide the comment indicator before sharing their screens!
After working with your colleague Frank to fully understand the business requirement for extending the comments features, you suggest creating:
An Enable/Disable Comment Mode button that displays or suppresses the aqua green comment indicator in data cells.
A text widget and button that allows planners to enter comments in an input field and use the Add Comment button to add them to the database. This includes a popup for an error message that will be displayed if the planner tries to add a comment without selecting a product group in the data table.
A fixed area in the story to display comments by product group. This includes a radio button to select specific comments in order to delete them.
A fixed area in the story to display the comment audit trail (who and when) information.
A button to delete comments.
A dropdown to display or add comments in the comment widget by product group.
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's comments features.
Enable/Disable Comment Mode
The following script is added to BTN_EnableComment - onClick to display/hide the comment indicators in a story:
The following script is added to TBL_Planning_Enabled - onSelect to run the script object when the table is selected:
Add Comments
The following script is added to BTN_Add_Comment - onClick to:
Display the Popup_Error if a data cell is not selected.
Read the user defined comment from the INF_Enter_Comment input field and add it to the selected data cell.
Refresh the comments displayed in the radio button and the textbox.
Code snippet
var sel = TBL_Planning_Enabled.getSelections();
var cellSelected = TBL_Planning_Enabled.getDataSource().getData(sel[0]);
if (cellSelected === undefined) {
Popup_Error.open();
}
else if (sel.length > 0) {
var comment = INF_Enter_Comment.getValue();
TBL_Planning_Enabled.getDataSource().getComments().addComment(sel[0], comment);
INF_Enter_Comment.setValue("");
SO_Comments.readComments();
}
The following script is added to Popup_Error - onButtonClick popup to close the error message that will appear if a data cell is not selected by the planner when trying to add a comment:
The following script is added to BTN_Delete_Comment - onClick to delete the data cell comments by its ID and refresh the comments displayed in the radio button and the textbox:
Code snippet
var sel = RB_CommentID.getSelectedKey();
TBL_Planning_Enabled.getDataSource().getComments().removeComment(sel);
SO_Comments.readComments();
Populate the Product Group Dropdown on Page Initialization
The following script is added to Page_1 - onInitialization to populate the DD_ProductGroup dropdown box with the dimension values of ProductGroup (except the value # unassigned) when a planner opens the story:
Code snippet
var ProductGroups = TBL_Planning_Enabled.getDataSource().getMembers("ProductGroup");
for (var x=0; x<ProductGroups.length; x++){
var ProductGroup = ProductGroups[x];
if (ProductGroup.id!=="#"){
DD_ProductGroup.addItem(ProductGroup.id,ProductGroup.description);
}
}