Skip to Content
Technical Articles
Author's profile photo Fabien AUBERT

How to schedule an analytic application for publication in SAP Analytics Cloud ?

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();
    
   Application.sendNotification({
         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";     

Where

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

Scheduling.publish();

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

Scheduling.isRunBySchedulePublication()

 

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

Application.sendNotification({
  …
  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

Assigned Tags

      27 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Marcos Carvalho
      Marcos Carvalho

      Nice article.

      I'd like to know if it's possible to send e-mail to non-SAP Analytics Cloud recipients using the method sendNotification(). I've tried it, but I was able to send e-mails only using SAP Analytics Cloud recipients.

      Best regards.

      Author's profile photo Fabien AUBERT
      Fabien AUBERT
      Blog Post Author

      HI Marcos,

      No you cant send notification to non-SAP Analytic Cloud recipients for security reasons. You can create a Team in SAC that contains a DL for those recipients and send the notification to this dedicated team.

      Kind Regards

       

      Author's profile photo Marcos Carvalho
      Marcos Carvalho

      Hi Fabien,

       

      Thank you for clarifying.

       

      Best regards.

      Author's profile photo Edward Wilson
      Edward Wilson

      Hi Fabien, Is this possible to use teams for "receivers"  in sendNotification() call?

      When using Ctrl+Space and accessing the user & team list selector only individual named users are visible. Also when hardcoding using "TEAMNAME" or "TEAM:TEAMNAME" format this still does not generate the sendNotification.

       

       

      Author's profile photo Fabien AUBERT
      Fabien AUBERT
      Blog Post Author

      Hi Edward,

      This is weird. On my SAC tenant I can select either users or teams as a recipient. It should work!!

      Best Regards

      Author's profile photo Edward Wilson
      Edward Wilson

      Hi Fabien,

      Thankyou for getting back to me.

      I've tested this functionality across 7 different tenants using the following code:

      Application.sendNotification({
      title: "notificationTitle",
      content: "content",
      isSendEmail: true,
      mode: ApplicationMode.Present,
      receivers: }); // <- Using Ctrl + Space to open the member selector and it returns only users.

      The tenants are all on release: 2022.8.13 (Client) 2022.8.10 (Server) bar one that is on 2022.8.7

      What version is the tenant you are using if I may ask? (Wondering if it is a release related limitation).

      Best Regards

       

      Author's profile photo Aditya Mishra
      Aditya Mishra

      Does the mobile push notification work only for IOS? can't receive notification on my android device.

      Author's profile photo Fabien AUBERT
      Fabien AUBERT
      Blog Post Author

      HI Mishra,

      Android devices are not supported yet for analytical application. But this is in our roadmap !!

      Kind Regards

      Fabien

      Author's profile photo Ramakrishnan Ramanathaiah
      Ramakrishnan Ramanathaiah

      Thank you Fabien for the blog.  Couple of question when you get a chance, could you please help.

      1. In SAC scheduling, is it possible to schedule the reports based on the Fiscal Calendar, instead of standard Calendar.
      2. The user wants to run certain reports based on Fiscal month, so the custom table is residing in the HANA CLOUD, so when ever we run the report, we need to identify the current date, pass it to the custom table on the HANA cloud, and get the Fiscal period. Is this possible in scheduling or any other way we can do this in SAC/HANA CLOUD.

      Kindly let me know when you have a moment.

       

      Regards

      Ramakrishnan Ramanathaiah

       

      Author's profile photo Fabien AUBERT
      Fabien AUBERT
      Blog Post Author

      Hi Ramakrishnan

      In SAC the calendar is always a standard calendar. There is no option to change it to a fiscal calendar.

      However you can enable a fiscal year at the level of a SAC model https://apps.support.sap.com/sap/support/knowledge/en/2571910

      Kind Regards

      Fabien

       

      Author's profile photo Fabien AUBERT
      Fabien AUBERT
      Blog Post Author

      Hi Ramakrishnan,

      No there is no option to switch the SAC calendar to a fiscal year.

      However you can enable a fiscal year to a SAC model.

      Kind Regards

      Fabien

      Author's profile photo Ramakrishnan Ramanathaiah
      Ramakrishnan Ramanathaiah

      Thank you very much Fabien. Got it.

      Regards

      Ramakrishnan Ramanathaiah

       

      Author's profile photo T M Prasad
      T M Prasad

      Hi Fabien,

      Thanks for this Nice Blog. Requesting your support on the below Point.

      Is it Possible to Attach the PDF for Notification also?. ( It is working fine for Scheduling Publication But the user needs to get the data only when an Exception happens and he would like to have this as an attachment)

       

      Regards,

      Prasad

      Author's profile photo Fabien AUBERT
      Fabien AUBERT
      Blog Post Author

      Hi Prasad,

      No you can't.

      Kind Regards

      Fabien

      Author's profile photo Vibhav Nallan
      Vibhav Nallan

      Hello Fabien, great article!

       

      Could you let me know when this feature will be supported for DWC Live data?

      Author's profile photo Arvind B Sharma
      Arvind B Sharma

      Hi,

      I am also getting below error when publishing in SAC on top of DWC.

      The report is refreshing fine.

      Is there some settings needs to be done on DWC/SAC side.

      Regards

      Arvind

      Author's profile photo Koen Hesters
      Koen Hesters

      Hi

      Fantastic stuff, trying to use it myself, but struggling with the layout of the notif. mail, can you help me out please? details : How to customize SAP Analytics Cloud Notification email | SAP Community

      Thanks for any kind of advice

      Koen

      Author's profile photo Fabien AUBERT
      Fabien AUBERT
      Blog Post Author

      Hi Koen,

      You can use the notification API "Application.sendNotification(notification: NotificationOptions)".  NotificationOptions is a JSON object. One of its properties is "content" (which correspond to the body of the email). It is in HTML format format with limited support, including the tags <i>, <b>, <u>, <a>, and <br>

      Kind Regards

      Fabien

      Author's profile photo Emanuel Schellner
      Emanuel Schellner

      Hi Fabien,

       

      thank you! Just a remark for those who could not make this work: the prerequisite to send notifications is: that your own mail server’s been configured on SAC. Otherwise only schedules can send emails.

      Thank you

      Emanuel

      Author's profile photo Yan Gerzon
      Yan Gerzon

      Hi,

      Lets say I count amount of tows in a table that is inside the applicaiton.
      If row amount is 0 i need to send an email.
      If i do not have my own email server and can only use the scheduling, how do i then make sure an email/notification is sent ONLY when the above condition is true?

      Author's profile photo Carlos Gonzalez
      Carlos Gonzalez

      Yan, can you please confirm what was replied to you after this specific question ? Thank you in advance for your feedback!

      Author's profile photo Yaniv Barel
      Yaniv Barel

      It was.

      Author's profile photo Carlos Gonzalez
      Carlos Gonzalez

      Thank Yaniv for your replu it is appreciated.

      One more thing when you say "IT WAS" by that you mean that they replied to this question and could you share what that answer was please?

      "If i do not have my own email server and can only use the scheduling, how do i then make sure an email/notification is sent ONLY when the above condition is true?

      Author's profile photo Yan Gerzon
      Yan Gerzon

      Hi,

      Thank you this was very helpful.

      Is there a way to remove the link to the analytical application from the mail?

      Author's profile photo murali m
      murali m

      @Fabien AUBERT

      Is there a way to send a email notification with PDF attachment on a click of a button in Analytics Designer? If yes do let me know. Thanks.

      I have also raised the same question in Improvement Request Details - Customer Influence (sap.com)

       

      Regards

      Murali.M

      Author's profile photo Bhuvnesh Gupta
      Bhuvnesh Gupta

      Fabien AUBERT  Hi, could you please provide more help on triggering email manually with filtered data.

      Author's profile photo Muthukkumaran KM
      Muthukkumaran KM

      Hi Fabien AUBERT,

       

      I faced an issue regarding the email notification while passing the threshold whenever the value is lesser than the given condition it is triggering the email but if the value is larger than the given condition also the mail is triggered and also everytime the application is on the run mode the email notification is triggered is there any solution for this.