SAP Analytics Cloud (SAC) Application Designer JavaScript APIs
Here’s a list of key JavaScript APIs available in the SAP Analytics Cloud (SAC) Application Designer, organized by category. These APIs are used to add interactivity, manipulate widgets, and control data in custom applications:
1. Application-Level APIs
Application.getApp()
: Reference the current application instance.Application.navigateToPage(pageId)
: Navigate to a specific page in the app.Application.setBusy(isBusy)
: Show/hide a loading spinner.Application.showMessage(type, message)
: Display alerts (info, error, warning, success).Application.getParameters()
: Retrieve URL parameters passed to the app.
2. Widget-Specific APIs
Widget.getWidget(widgetId)
: Get a widget instance by its ID.Widget.setVisible(widgetId, isVisible)
: Show/hide a widget.Widget.setData(widgetId, dataSource)
: Bind a widget to a data source.Widget.refresh(widgetId)
: Refresh a widget’s data.Widget.setProperty(widgetId, property, value)
: Modify widget properties (e.g., color, title).
3. Data & Model Handling APIs
DataSource.getDataSource(dataSourceId)
: Reference a dataset or model.DataSource.refreshData(dataSourceId)
: Refresh data from the source.DataSource.setFilter(dataSourceId, filter)
: Apply filters to a dataset.DataSource.createMemberFormula(dimension, formula)
: Define calculated members.DataModel.getPlanningModel()
: Access planning-specific functions (write-back, simulations).
4. Variable & Parameter APIs
Variable.getVariable(variableId)
: Retrieve a variable instance.Variable.setValue(variableId, value)
: Set a variable’s value.Variable.getValue(variableId)
: Fetch the current value of a variable.Variable.getDisplayValue(variableId)
: Get the user-friendly display value.
5. Event Handling APIs
Event.onClick(widgetId, callback)
: Trigger actions on widget click.Event.onDataChange(dataSourceId, callback)
: Execute logic when data changes.Event.onPageNavigate(callback)
: Run code during page transitions.Event.onVariableChange(variableId, callback)
: React to variable value changes.
6. Utility & Helper APIs
Utilities.formatDate(date, format)
: Format dates for display.Utilities.formatNumber(value, format)
: Format numeric values.Utilities.HttpRequest(url, options)
: Make HTTP requests to external APIs.Logger.log(message)
: Print debug messages to the console.MessageBox.confirm(message, callback)
: Show a confirmation dialog.
7. Planning-Specific APIs
Planning.saveData()
: Commit planning data changes.Planning.runAllocation(dataSourceId)
: Execute allocation rules.Planning.enableDataEntry(widgetId)
: Allow write-back in tables/charts.Planning.getVersionInfo()
: Retrieve planning model version details.
8. Advanced Scripting APIs
Chart.addDrillDownDimension(dimension)
: Dynamically add drill-downs to charts.Table.setSorting(widgetId, column, order)
: Sort table columns programmatically.Map.setLayerVisibility(layerId, isVisible)
: Control map layers.Script.include(scriptUrl)
: Import external JavaScript libraries.
Example Usage
// Navigate to a page and refresh a chart
Application.navigateToPage("sales_overview");
const chartWidget = Widget.getWidget("chart_sales");
Widget.refresh(chartWidget);
// Set a variable and filter data
Variable.setValue("region_filter", "EMEA");
DataSource.setFilter("sales_data", {
operator: "EQ",
dimension: "Region",
value: Variable.getValue("region_filter")
});
// Show a confirmation dialog
MessageBox.confirm("Save changes?", function(result) {
if (result === "OK") {
Planning.saveData();
}
});
Key Notes
- Deprecated APIs: Older functions like
Application.gotoPage()
may still work but are replaced by newer equivalents (e.g.,navigateToPage()
). - Security Restrictions: Some APIs (e.g.,
Utilities.HttpRequest
) require CORS configuration or admin permissions. - Script Debugging: Use
Logger.log()
and the Script Editor Console to debug. - Documentation: Always refer to the latest SAC Scripting API Reference for updates.
Let me know if you need examples for specific use cases!
No comments:
Post a Comment