Skip to Content

[SAP HCP-IS ]Exception Sub Process-How to create Alert body for Error Notification

This blog describes how to create and handle dynamic alert notification inside the Exception Sub Process in SAP HCI.
About Exception Sub Process:
Exception Sub Process can catch any exceptions thrown in the integration process and process them.Below parameters will give more details of the the exception raised.

  • ${exception.message} : Short description of the Exception.
  • ${exception.stacktrace} : Complete trace of the Exception raised.

Use Case:
Lets create Custom integration where we will pull the File from SFTP server and save it in data store.

1. Sender: Add Sender component from integration designer pallete.
2. Channel: Configure SFTP sender channel which picks file from SFTP server.

3. Content Modifier: To read the key details of incoming message.In our case we are capturing input file name.4. Script:  To read the tenant details in run time( in our case tenant id is of 5 character length like X1234 ,L1234 ) and stores it in property.
5. Script: Erroneous script to forcefully fail the message and trigger exception.
6. Data Store: Store the output ( In the above case its just added to have an end to end flow ).
7. Content Modifier: Content Modifier [ Body ] to build the email body.

Content Modifier [ Header ] to set the exception stack trace into header which is later sent as a attachment.
8. Send: Send step is used to send the message to External Systems Asynchronously.
9. Channel: Mail adapter to send the exception details to mail receiver.
Once you are done with above configuration save and deploy the Integration Project.
Place a test file in SFTP share and you will be able to find the below Error Alert Mail triggered from Exception Sub Process.

Further Improvements and Limitations:
1. XSLT mapping with HTML can be used in addition to above use case inside the Exception Sub Process to improvise the look and feel of the email body.
2. Custom Exception can be created and raised using Groovy Script.
3. You cannot catch exceptions of local integration process in the main integration process.
4. As of now Exception Sub Process is not available in WEBUI( may be it is present in the SAP road map ).
Exception Sub Process is very useful for handling Exceptions raised in Integration process although it requires further improvements.
[1] Content Modifier:
[2] Mail Adapter:
[3] Exception Sub Process:

Sriprasad Shivaram Bhat

You must be Logged on to comment or reply to a post.
  • Thanks Sri..

    Very informative..

    We are working on SF integration, where we need to fetch employee records and send those records to SFTP server via SAP HCI. We have placed transformation rules in HCI to validate the data coming from SF.. Just wanted to check what is the possibility to check the below

    1. Total Number of employees processed through this interface.
    2. Total Number of employees processed successfully.
    3. Total Number of employees processed unsuccessfully


    Thanks in advance..



  • I am using your code in sub process exception and when trying to execute am getting the substring can't be invoked. Please find the code which am using below and please let me know if you see any error. I have also pasted the error message for your reference.

    The integration developer needs to create the method processData
    This method takes Message object of package
    which includes helper methods useful for the content developer:
    The methods available are:
    public java.lang.Object getBody()
    public void setBody(java.lang.Object exchangeBody)
    public java.util.Map<java.lang.String,java.lang.Object> getHeaders()
    public void setHeaders(java.util.Map<java.lang.String,java.lang.Object> exchangeHeaders)
    public void setHeader(java.lang.String name, java.lang.Object value)
    public java.util.Map<java.lang.String,java.lang.Object> getProperties()
    public void setProperties(java.util.Map<java.lang.String,java.lang.Object> exchangeProperties)
    public void setProperty(java.lang.String name, java.lang.Object value)
    import java.util.HashMap;
    def Message processData(Message message) {
    def body = message.getBody();
    // Fetch Application URL
    String appUrl = System.getenv("HC_Application_URL");
    // Retrieve HCI tenant name
    String TMN_ShortName = appUrl.substring(8,13);
    // Set Tenant name to property
    message.setproperty ("P_Tenant_Name",TMN_ShortName);
    return message;

    Message processing failed.
    javax.script.ScriptException: java.lang.Exception: java.lang.NullPointerException: Cannot invoke method substring() on null object@ line 23 in script21.groovy, cause: java.lang.NullPointerException: Cannot invoke method substring() on null object




  • Hello Hari,

    You must correct the line where you are pulling environment details.Since there are no details being pulled its giving an error.

    Correct One: String appUrl = System.getenv("HC_APPLICATION_URL");

    Environment variables are case sensitive and you must pass the above one it will solve your issue.


    Sriprasad Shivaram Bhat


  • /
    • Yes, I know where you have used in the code. My question is the naming convention(HC_APPLICATION_URL) which you have used is retrieved from somewhere on the tenant and is it a standard. The reason I am asking is when used a proper case it was throwing an exception.

      Please let me know.



  • Hello Hari,

    I am able to successfully retrieve the Tenant ID using below script may be you can try copy pasting the same.

    import java.util.HashMap;
    def Message processData(Message message) {
          //Retrieve Body 
          def body = message.getBody();
          //Function to fetch application url of HCI Tenant
          String appUrl = System.getenv("HC_APPLICATION_URL");
          //Logic to retrieve only Tenant Name      
          String TMN_ShortName=appUrl.substring(8,13)
          //Set the Tenant name to Property
          return message;


    Sriprasad Shivaram Bhat


  • Is there any way to set a cadence to when these alerts are sent?  We have a flow that was built and it checks every 10 minutes for new data (we need the systems in sync as much as possible). And if there is an API error, for example, we will get an error email every 10 minutes.  Is it possible to send once an hour or some other time frame?  We ultimately just need to be notified the first couple times that there is an issue.



    • Yes you can do it with some more extra efforts:(,inside Exception Sub Process instead of Send Step you can have a data store ( with Global Scope ) and store every error message in some XML format.

      Create one more flow which is Scheduled for every hour to pull the data from the data-store which was created earlier in Exception SubProrcess and send an alert email to Support Team or whomever you want to send.


      Sriprasad Shivaram  Bhat

  • Hi Sriprasad,

    This solution is fine if we want to get mails for 1 or 2 integrations.

    But in our case we have around 60+ integrations in our tenant and we need this mail notification to be triggered immediately for each message failure which is occurring in our tenant for all these integrations.

    It's difficult to configure this Exceptional sub process in all our integrations.

    Any possibility to simplify this and achieve or any other alternative ways.?



    • Hello Deva,

      If you want to receive the email for each integration then you have to add it explicitly in 60+ scenarios. In case if you are yet to create custom integration you can have some simple flow with above steps and save it as Template.Later for other integration,template with error handling steps would be starting point.


      Sriprasad S Bhat

  • Hello Sriprasad,

    Thanks for your quick response.

    Plz provide further details on how to use Save as template and where I can get that.


    one more clarification: I tried as you have mentioned above.

    I am getting the mail if there is any exception/error in the integration. But messages are showing as completed even if there is any exception/error. It should be shown as failed message right.?

    But no messages shown in failed status even if there is error in the integration, showing all messages are completed. While opening MPL Logs only I am able to check whether there is any error or any issue. Why is it so.?




  • Excellent blog!! kudos to you. Thank you for sharing. Didn't knew we could retrieve the tenant name and system URL.

    Do you know if we could use externalized parameters in the email body ?