en Scripting Documentation (comments)

graphomate comments integrate seamlessly into the SAP Analytics Cloud. Scripting is also supported in the Application Designer of the SAP Analytics Cloud.

The properties shown in the property sheet can be retrieved and set by scripting from the component. There are also methods that make it easy to set contexts for comments:

createDataContext(key: string, value: string): DynamicContext;

A data context can be created via this method, which can then be set via the setDynamicContexts method, which is passed an array of contexts. A data context usually contains a combination of dimension and member. For example, the key is "year" and the value is "2021".

createDataContextWithText(key: string, value: string, keyText: string, valueText, string): DynamicContext;

If your data source makes a difference between IDs for dimensions and members and their display text, this method can be used in the same way as createDataContext.
In addition, it is possible to set the display texts. For example, here the key is "CAL_YEAR" and the keyText is "Year".

createEnvironmentContext(key: string, value: string): DynamicContext;

An environment context can be used to limit the comment space to, for example, a specific environment or dashboard. Here, the key could be something like "Dashboard Name" and the value could be "Global Sales 2021".

addOrReplaceDataContext(key: string, value: string): void;

This method works in the same way as createDataContext. However, it adds or changes the context defined here directly to the widget. The path through setDynamicContexts is therefore not necessary.

addOrReplaceDataContextWithText(key: string, value: string, keyText: string, valueText: string): void;

The function parameters behave like those of the createDataContextWithText method. As in addOrReplaceDataContext, however, the context is also added or changed directly.

addOrReplaceEnvironmentContext(key: string, value: string): void;

The parameters work in the same way as createEnvironmentContext. However, they are added or modified directly.

removeDataContext(key: string): void;

Removes the data context with the key from the context space of the comment widget.

removeEnvironmentContext(key: string): void;

Removes the environment context with the key from the context space of the comment widget.

setSelectedData(selectedData: SelectionContext[]): void; (ab Version 1.20224.1)

The data selected by click in a graphomate visualization can thus be transferred to the comments widget to create data contexts.

setDynamicContexts(dynamicContexts: DynamicContext[]): void; (ab Version 1.20231.0)

Contexts created via the create*Context methods can be used here to reset the entire dynamic contexts. The previous status is overwritten in the process.

addOrReplaceContexts(contexts: DynamicContext[]): void; (ab Version 1.20231.0)

Setting several contexts at the same time leads to inconsistencies when using addOrReplace*Context. This method provides a remedy because it enables several contexts created via create*Context to be transferred to the widget in parallel.

removeContexts(contexts: DynamicContext[]): void; (ab Version 1.20231.0)

To remove several contexts at the same time, this method should be used to pass contexts created with create*Context to this method instead of individual calls to remove*Context. These are then removed from the state of the widget. In the create*Context method, the key or the value can also be set as an empty string. Then all contexts to which only the defined key or value applies are removed.

 

 

Examples

To set a data context depending on the selection of a value in a drop-down field, the following code can be adjusted:

var countryMember = Country_Dropdown.getSelectedKey(); if (countryMember === "None") { Chart_1.getDataSource().setDimensionFilter("Country_Region", []); graphomate_comments_1.removeDataContext("Country_Region"); } else { Chart_1.getDataSource().setDimensionFilter("Country_Region", countryMember); graphomate_comments_1.addOrReplaceDataContext("Country_Region", countryMember); }

The following code sets the information about a data point selected in a graphomate chart as contexts for the comments widget:

graphomate_comments_1.setSelectedData(graphomate_charts_1.getSelectedData()); // ab Version 1.20224.1

Multiple contexts can be changed or added at the same time as follows

var regionContext = graphomate_comments_1.createDataContext("region", "North"); var countryContext = graphomate_comments_1.createDataContext("country", "Germany"); graphomate_comments_1.addOrReplaceContexts([regionContext, countryContext]);

To remove the contexts added above at the same time, you can do the following

If the two contexts above are to be removed, regardless of what value they are set to, empty strings can be used:

To reset all the dynamic contexts that have been added and to remove the ones that were previously set, proceed as follows:

Â