Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
Showing results for 
Search instead for 
Did you mean: 
Schedule an analytical application for publication is a powerful feature available in Analytics Designer to meet business needs. In this blog post I will show you how to use this feature through a typical use case.

Business Use case

John Smith, owner of a bakery business, needs to monitor the planned margin for the next 2 weeks. If the planned margin is below 0, he needs to be alerted so that he can change his plans to regain a positive operating margin.

Use Analytics Designer

In John's case, Analytics designer is the perfect answer. It will involve creating an analytical application that will send an alert when the margin is negative and allow John to run simulations to optimize the production plan to reach the targeted margin again.

I will concentrate the rest of the blog post on the alerting part.

John receives a notification on a margin issue. Compared to current planning, the expected margin is – 1.38%.

In the notification email he can access to the application to visualize the figures

or access directly to the simulation part.


Create a notification in Analytics Designer

Let's see how sending the alert has been implemented in the application

When the application is opened it sends an email notification if the margin is below 0. In the “onInitialization” event we have the following code
if (margin < 0) {
var notificationTitle = "Your margin forecast for calendar week 11.";
var notificationContent = NotificationHelper.GenerateNotificationContent();

title: notificationTitle,
content: notificationContent,
isSendEmail: true,
mode: ApplicationMode.Present,
receivers: ["FAUBERT"]

The method sendNotification() takes a JSON object as a parameter.

Let’s review the main properties:

  • “title”: title of your email (and your notification in SAC)

  • “isSendEmail”: is set to true to receive an email notification (if this parameter is set to false you will receive a notification directly in SAC)

  • “receivers”: specify the SAC users that will receive the email.

  • “content”: the content of your message in your email (in HTML format with limited support, including the tags <i>, <b>, <u>, <a>, and <br>)

    • Here is the content of the current email:

"According to the latest online price information from supermarkets, we detected a significant data change of total material cost. We will be able to generate a total profit of <b><u>" +
profit.toString() + "</b></u> USD, with a margin of <b><u>" + (100*margin).toString() + "%</b></u>. In order to improve this forecast, we have created two proposals. <br><br>" +
"Click " + "<a href='" + APP_LINK_V1 + "'>here</a>" +
" to open the application. <br>" +
"Click " + "<a href='" + APP_LINK_WITH_PROPOSAL + "'>here</a>" +
" to find out the proposal details. <br><br>" +
"SAP Analytics Cloud";

APP_LINK_V1 = NavigationUtils.createApplicationUrl(Application.getInfo().id, [UrlParameter.create("mode", "present")]);

This link opens the application in Present mode.
 APP_LINK_WITH_PROPOSAL = NavigationUtils.createApplicationUrl(Application.getInfo().id, [UrlParameter.create("mode", "present"), UrlParameter.create("p_show_proposal", "true")]);

This link opens directly the 2nd tab of the application where you can run the simulations.
Notice that in these 2 links we pass some URL parameters.


Scheduling publications in Analytics Designer

To send a notification, the prerequisite is to schedule the application (For more details on Scheduling Publications in SAP Analytics Cloud please have a look at the master blog post here) . This means that you will need to create an “Export to PDF” technical component into your application.

Then at runtime you will have to schedule your application.

Let’s review the different scheduling options:

  • Schedule my application every week on Sunday night.

  • Generate an Analytic Application link

  • Set the value of my script variables which are exposed via URL Parameter

  • Specify the SAP and non-SAP recipients that will receive the email. (The scheduling will generate an email containing a pdf)


Once the scheduling task is completed, 2 emails will be sent:

  • One containing the generated pdf

  • One containing the notification

As a reminder the recipients of these 2 emails can be different in case you want that your end-user receives only the notification email.


Script Variables management

As we saw earlier the notification email contains 2 hyperlinks. The first one allows you to open the application home page where you can see among other things the forecast margin. The second link opens directly the page where we can make simulations to improve our forecast margin.

To be able to open the second page, we had to change the default value of the script variable "p_show_proposal" to true. When sending a notification, we can change the values of the script variables by passing a URLParameter.

When scheduling an application, the values of the variable scripts can be also customized. You can define the value directly in the schedule publication dialog by turning on the option Customize Script Variable

Schedule a Bookmark

You can also schedule a bookmark from an application. Let's imagine that you have saved a bookmark from an application corresponding to the data of France. By scheduling this bookmark, you will have in the pdf generated only the updated data for France. And the link generated in the email will point to the bookmark and not to the original application.


More options


Log message during the scheduling

You can log a message during the scheduling of an application. This message will be displayed in the scheduling status details.
Scheduling.logMessage(SchedulingMessageType.Info, "This is an Info message");
Scheduling.logMessage(SchedulingMessageType.Error, "This is an Error message");
Scheduling.logMessage(SchedulingMessageType.Warning, "This is a Warning message");

Once the schedule publication is finished, you will see the following messages in the scheduling status details

In addition to manual messages, Analytics Designer provides also some system error message which helps end users to view detailed information for failures and errors for a scheduling task.

  • ExportToPDF technical component is missing

  • Variable input dialog is open for user input. That blocks the workflow.

  • The script execution could failed for some error.

  • Error happens when exporting pdf

  • The selected bookmark doesn’t exist anymore.

  • Error happened when processing Data Change Insights

  • publish() call is essential for scheduling in manual mode. But app developer could forget to do that or script is changed later.

Trigger manually the pdf generation

By default, the pdf generation is automatically triggered after the Application - onInitialization event.

You may want to wait for another event to run before generating your pdf. An application developer may initialize some widget status and apply filters or variables via a Timer after the Application - onInitialization event. In this case you will have to use the scheduling API.

First, you will have to select the option “Manually generate PDF export via API”. This option belongs to the Canvas element in the outline panel

And then in your script you will have to add the following code

If there's no manual triggering job, the task will be failed directly.

The developer will have 60 seconds to finish the manual execution of the scheduling job, otherwise the task will be failed directly.

Execution of an application

A developer will be able to implement different behaviors depending on whether an application is running in a browser (user interaction) or in the background (scheduling job). To do so, he will use the API


Notification for Mobile application

With the Q4 2020 QRC you will be able to send notification to iOS native notification with SAC mobile application. A new property will be available

isSendMobileNotification: true



In Conclusion

We have learned how to schedule an application. The result is the generation of a pdf sent by email. We also learned how to send a notification using the SendNotification API. The result is a notification sent by email or/and a notification sent directly into SAC. To be able to receive notifications you need to schedule your application.

I hope this blog post clarifies the use of scheduling and notification features in Analytics Designer