Skip to Content
Technical Articles
Author's profile photo Srishti Gupta

Exception Handling in SAP Cloud Integration I-Flows via Email Notifications

Hi Folks

During the journey of SAP Cloud Integrations, there was a requirement that we have to trigger emails for every failure of message/transaction respective to Integration flows occurring in the SAP Cloud Integration tenant. This is not just it. The recipient email addresses can be different as per the owner of Integration flows.

To cater to the solution, I have designed the integration flow and thought of sharing it as a blog post.

For an instance, we have an integration flow that is responsible to transmit the file from one SFTP location to another. Whenever there is any failure for this flow during file transmission, the exception sub-process should capture the exception message and send it to the owner of the flow to enable him to take further necessary actions.

Below is the integration flow snapshot of the Integration flow:


Steps performed for Exception Subprocess in Integration flow:

Exception Subprocess has a Content Modifier that captures the message headers and prepares an XML Message body and posts the same using ProcessDirect adapter to Exception Integration Main flow designed for posting the emails to integration flow respective owners.

Exception Subprocess:-

Content Modifier (named as Send Exception Details):
Message Header:

Expression – stacktrace: ${exception.stacktrace}

Constant – InterfaceID: IFLOW_01 (you can set this as anything unique name to use it as I-flow specific Id)

Message Body:

<?xml version="1.0" encoding="UTF-8"?>
Process Direct Adapter:


Main Exception Handling Flow:

Using the ProcessDirect adapter at the sender end and keeping the same endpoint, the exception message is received in Exception Handling Main Flow.

Sender side Process Direct Snapshot below:


Content Modifier (named as Get Header/Properties):

Message Header:


Exchange Property:


Groovy Script (named as Call Value Map):

import java.util.HashMap;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.lang.*;
import java.util.*;

def Message processData(Message message)
    def body = message.getBody(java.lang.String) as String;
    def map = message.getHeaders();
    def InterfaceName = map.get("InterfaceId") as String;
    def obj = ITApiFactory.getApi(ValueMappingApi.class, null);
    def mappedValue = obj.getMappedValue("InterfaceDetails", "InterfaceName", InterfaceName, "InterfaceDetails", "RecipientName");

    if (mappedValue == null)
    { throw new IllegalStateException("No valuemapping maintained for Interface: "+InterfaceName);
    message.setProperty("RecipientName", mappedValue);
    return message;


Mail Adapter Configuration:

In the Connection tab, the connectivity details are maintained. In the Processing tab of the mail adapter, below is the snapshot of the configuration done:


Mail Body:

Hi Team Members
This email is to notify you that an interface has failed in the middleware SAP Cloud Integration.</br>
Here are the details about the interface, and the exception caught which would help you analyze this issue further:</br>
<table style="width:50%">
		<td style="background-color:#5B8AB6;color:white">
		<td style="background-color:#5B8AB6;color:white">
		<td style="background-color:#5B8AB6;color:white">
			<b>Message ID</b>
		<td style="background-color:#5B8AB6;color:white">
			<b>Integration Flow Name</b>
	</tr>  <tr>
		<td style="background-color:#5B8AB6;color:white">
			<b>Exception Message</b>
<i>This is an auto-generated email from the middleware (SAP Cloud Integration). Please do not reply to this email.</i>


The above Groovy is calling the Value Mapping maintained as per the InterfaceID that we had set in the above steps as Constant in Exception Subprocess Content Modifier to maintain a unique Iflow-specific ID which would enable sending the email as per Iflow respective owners.

Value Map Snapshot:

In the value map, we can add more entries and correspond to them, we can assign the desired email IDs (separated with commas) to which email should be sent for that specific iFlow failure.


This is how we can handle the exceptions for the iFlows and send email notifications to desired emails.

Hope this blog post would add value to SAP Cloud Integration Community.



Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Raul Vega
      Raul Vega

      Thanks for sharing, very useful.