How To Trigger Automated Email Notifications Based on KPI Thresholds in SAP Analytics Cloud
Share

[[{“value”:”

Introduction

In many business scenarios, dashboards are expected to do more than just display KPIs. Business users also expect proactive alerts whenever critical numbers cross a certain threshold so that immediate action can be taken.

Recently, I worked on a requirement in SAP Analytics Cloud (SAC) where users needed to receive automatic notifications whenever a KPI exceeded a predefined limit. The alert had to be sent both as  an SAC notification and as an email. Another important requirement was that the process should run automatically on a specific day of the month without users having to open the dashboard manually.

In this blog, I’ll walk through the approach that was implemented using SAC scripting APIs such as getResultSet() and sendNotification() along with scheduled story publication.

Business Requirement

The requirement was straightforward but very useful from a business monitoring perspective.

The business wanted to:

  •             Monitor a KPI available in an SAC dashboard
  •             Compare the KPI value against a defined threshold
  •             Trigger an alert whenever the threshold condition is met
  •             Send email notifications to a predefined group of users
  •             Deliver alerts through: SAC notifications ,  Email notifications       
  •             Automate the entire process so that alerts are triggered on a scheduled date even if  nobody opens the dashboard

For example, if a KPI value becomes greater than 1000, users should automatically receive an alert.

Solution Overview

The solution was implemented using SAC Application Designer / Optimized Story scripting capabilities.

The main logic was written inside the On Initialization event of the story. Whenever the story initializes, the script reads the KPI value directly from the chart using the getResultSet() API.

The retrieved value is then converted into a numeric format and compared against the threshold value. If the condition is satisfied, the sendNotification() API triggers both SAC notifications and email alerts for the configured users.

To automate the process, the story publication was scheduled monthly to developers ID. During the scheduled execution, the story initializes automatically, which in turn executes the notification logic without requiring manual dashboard access.

High-Level Process Flow

The overall process works as follows:

  1.           The SAC story/dashboard initializes
  2.           The On Initialization script gets triggered
  3.           The script reads the KPI value from the chart using getResultSet()
  4.           The KPI value is converted into numeric format
  5.           The value is validated against the threshold
  6.           If the condition is met, a notification is prepared
  7.           SAC notification and email are sent to the configured users
  8.           Story publication scheduling automates the execution on the required date

During scheduled execution, the script runs automatically and sends alerts if needed.

Prerequisite

Before implementing this solution, ensure that email notifications are enabled in SAP Analytics Cloud.

Himanshu_Sharma_26_1-1780049937568.png

 

Technical Implementation

1. Fetching KPI Value from Chart

The KPI value can be accessed using the getResultSet() API available on charts and tables.

 Below is the logic used to fetch the KPI value:

 var check_data = Chart_1.getDataSource().getResultSet()[0][Alias.MeasureDimension].rawValue;       This retrieves the raw KPI value from the chart result set.

2. Formatting the KPI Value

The returned value may sometimes be in string format, so it is important to convert it into a numeric value before comparison.

var value = Number.parseInt(check_data);

3. Threshold Validation

Once the value is converted, it can be validated using a simple conditional statement.

var notificationContent = “”;
var title = “”;
if(value > 1000){
title = “Alert – The value is greater than 1000”;
notificationContent = “Dear User, Please be informed that the value is greater than 1000”;
}
else{
title = “Key figures look good”;
notificationContent = “Key figures look good”;
}

4.  Sending Notifications

The sendNotification() API is used to send alerts to specific SAC users.

Application.sendNotification(
{
title: title,
content: notificationContent,
receivers: [“user_id”],
mode: ApplicationMode.Present,
isSendEmail: true
});

This sends:

  •             An SAC notification
  •             An email notification (if email settings are enabled)

Complete Script

var check_data = Chart_1.getDataSource().getResultSet()[0][Alias.MeasureDimension].rawValue;
console.log(check_data);
var value = Number.parseInt(check_data);
var notificationContent = “”;
var title = “”;
if(value > 1000){
title = “Alert – The value is greater than 1000”;
notificationContent = “Dear User, Please be informed that the value is greater than 1000”;
}
else{
title = “Key figures look good”;
notificationContent = “Key figures look good”;
}
Application.sendNotification(
{
title: title,
content: notificationContent,
receivers: [“user_id”],
mode: ApplicationMode.Present,
isSendEmail: true
});

Automating Alerts Using Scheduled Publication

Initially, notifications were getting triggered only when users opened the dashboard manually.

However, the requirement was to run the alerting process automatically on a specific day every month.

To achieve this, the SAC story publication feature was used.

The story was scheduled for publication to a specific user on the required date. During the scheduled execution, the story automatically initialized in the background, which triggered the On Initialization script.

As a result:

  •             KPI validation happened automatically
  •             Threshold conditions were checked
  •             Notifications and emails were sent automatically whenever the condition was met

This approach helped in building a simple but effective automated KPI monitoring mechanism inside SAP Analytics Cloud without requiring any external integration or custom scheduling tools.

OUTPUT EMAIL :

Himanshu_Sharma_26_3-1780050425781.png

Final Thoughts

This solution is very useful for proactive business monitoring scenarios where users need immediate visibility into KPI fluctuations.

Using SAC scripting APIs along with scheduled publication makes it possible to build lightweight alerting mechanisms directly within SAP Analytics Cloud.

Some additional enhancements that can be explored:

  •             Dynamic threshold configuration
  •             Multiple KPI monitoring
  •             Role-based recipient management
  •             Integration with external notification channels
  •             Exception dashboards for alert tracking

I hope this blog helps anyone looking to implement automated KPI-based alerts in SAC.

If you are here, thank you so much for taking out your time to read this. Your feedback will be highly appreciated.

Thanks,
Himanshu

 

 

“}]] 

  Read More Technology Blog Posts by Members articles 

#abap

By ali

Leave a Reply