Sei sulla pagina 1di 20

1/28/2020 [SAP HCP-IS ]Exception Sub Process-How to create Alert body for Error Notification | SAP Blogs

Community

Ask a Question Write a Blog Post Login

Sriprasad Shivaram Bhat


January 16, 2017 2 minute read

[SAP HCP-IS ]Exception Sub Process-How to create Alert body for Error Noti cation
Follow RSS feed Like

14 Likes 8,946 Views 20 Comments

Introduction:
This blog describes how to create and handle dynamic alert noti cation 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.

https://blogs.sap.com/2017/01/16/sap-hcp-is-exception-sub-process-how-to-create-alert-body-for-error-notification/ 1/20
1/28/2020 [SAP HCP-IS ]Exception Sub Process-How to create Alert body for Error Notification | SAP Blogs

1. Sender: Add Sender component from integration designer pallete.


2. Channel: Con gure SFTP sender channel which picks le from SFTP server.

3. Content Modi er: To read the key details of incoming message.In our case we are capturing input le name.

https://blogs.sap.com/2017/01/16/sap-hcp-is-exception-sub-process-how-to-create-alert-body-for-error-notification/ 2/20
1/28/2020 [SAP HCP-IS ]Exception Sub Process-How to create Alert body for Error Notification | SAP Blogs

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 ow ).
7. Content Modi er: Content Modi er [ Body ] to build the email body.

Content Modi er [ Header ] to set the exception stack trace into header which is later sent as a attachment.
https://blogs.sap.com/2017/01/16/sap-hcp-is-exception-sub-process-how-to-create-alert-body-for-error-notification/ 3/20
1/28/2020 [SAP HCP-IS ]Exception Sub Process-How to create Alert body for Error Notification | SAP Blogs

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 con guration save and deploy the Integration Project.
Place a test le in SFTP share and you will be able to nd the below Error Alert Mail triggered from Exception Sub Process.

https://blogs.sap.com/2017/01/16/sap-hcp-is-exception-sub-process-how-to-create-alert-body-for-error-notification/ 4/20
1/28/2020 [SAP HCP-IS ]Exception Sub Process-How to create Alert body for Error Notification | SAP Blogs

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 ).
Conclusion:
Exception Sub Process is very useful for handling Exceptions raised in Integration process although it requires further improvements.
References:
[1] Content Modi er:
https://uacp.hana.ondemand.com/http.svc/rc/PRODUCTION/93810d568bee49c6b3d7b5065a30b0 /1/en-US/frameset.html?
2c667a12a0a545d2ad4210e070479312.html
[2] Mail Adapter:
https://uacp.hana.ondemand.com/http.svc/rc/PRODUCTION/93810d568bee49c6b3d7b5065a30b0 /1/en-US/frameset.html?
08af047a0c0145ab8742b946c 7bcd7.html
https://blogs.sap.com/2017/01/16/sap-hcp-is-exception-sub-process-how-to-create-alert-body-for-error-notification/ 5/20
1/28/2020 [SAP HCP-IS ]Exception Sub Process-How to create Alert body for Error Notification | SAP Blogs

[3] Exception Sub Process:


https://uacp.hana.ondemand.com/http.svc/rc/PRODUCTION/93810d568bee49c6b3d7b5065a30b0 /1/en-US/frameset.html?
f090fd40347c4cccba6c566193f76624.html

Regards,
Sriprasad Shivaram Bhat

Alert Moderator

Assigned tags

SAP Cloud Platform Integration for process services | SAP Cloud Platform Integration tools | SAP Process Integration |

Related Blog Posts

How to Integrate S4Hana Cloud and On-premise System Using SAP Cloud Platform Integration – Part2
By Pavan kumar , Jun 12, 2018

Blog 4: Modelling Exceptions in Integration Flows (SAP Cloud Platform Integration)


By Sujit Hemachandran , Jan 12, 2015

Con guring Alerts IN NW BPM


By Former Member , Jul 11, 2016

Related Questions

https://blogs.sap.com/2017/01/16/sap-hcp-is-exception-sub-process-how-to-create-alert-body-for-error-notification/ 6/20
1/28/2020 [SAP HCP-IS ]Exception Sub Process-How to create Alert body for Error Notification | SAP Blogs

Is it possible to capture the exceptions and send that to mail ID by using scripts in SAP HCI.?
By Devaraj R , Jun 12, 2017
How to handle exception in HCI IFLow
By Poornapragna TS , Mar 06, 2017

Error Handling in SCP-Integration Services


By Amber Badam , Oct 19, 2017

20 Comments

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

Aditya W. Sharma

January 16, 2017 at 11:45 am

A very good and informative blog, thanks Sri.

Like (1)

aravind pujari

January 16, 2017 at 5:47 pm

Hi Sriprasad,

Very informative blog, thanks for sharing.

https://blogs.sap.com/2017/01/16/sap-hcp-is-exception-sub-process-how-to-create-alert-body-for-error-notification/ 7/20
1/28/2020 [SAP HCP-IS ]Exception Sub Process-How to create Alert body for Error Notification | SAP Blogs

Like (1)

Former Member

February 7, 2017 at 3:01 am

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..

Aman

Like (2)

Former Member

February 27, 2017 at 11:29 pm

https://blogs.sap.com/2017/01/16/sap-hcp-is-exception-sub-process-how-to-create-alert-body-for-error-notification/ 8/20
1/28/2020 [SAP HCP-IS ]Exception Sub Process-How to create Alert body for Error Notification | SAP Blogs

I am using your code in sub process exception and when trying to execute am getting the substring can’t be invoked. Please nd 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 com.sap.gateway.ip.core.customdev.util
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 com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
//Body
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
Thanks

https://blogs.sap.com/2017/01/16/sap-hcp-is-exception-sub-process-how-to-create-alert-body-for-error-notification/ 9/20
1/28/2020 [SAP HCP-IS ]Exception Sub Process-How to create Alert body for Error Notification | SAP Blogs

HS

Like (0)

Sriprasad Shivaram Bhat | Post author

February 28, 2017 at 7:11 am

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.

Regards,

Sriprasad Shivaram Bhat

Like (0)

Hari Sonnenahalli

February 28, 2017 at 3:33 pm

Sri-

 
https://blogs.sap.com/2017/01/16/sap-hcp-is-exception-sub-process-how-to-create-alert-body-for-error-notification/ 10/20
1/28/2020 [SAP HCP-IS ]Exception Sub Process-How to create Alert body for Error Notification | SAP Blogs

Thanks for quick reply. One quick question, Where did you provide the environment variable (“HC_APPLICATION_URL“).

Please let me know.

Thanks

HS

Like (0)

Sriprasad Shivaram Bhat | Post author

February 28, 2017 at 3:39 pm

Hello Hari,

Please check below

https://blogs.sap.com/2017/01/16/sap-hcp-is-exception-sub-process-how-to-create-alert-body-for-error-notification/ 11/20
1/28/2020 [SAP HCP-IS ]Exception Sub Process-How to create Alert body for Error Notification | SAP Blogs

Like (0)

Hari Sonnenahalli

February 28, 2017 at 7:30 pm

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.

Thanks

HS

Like (0)

https://blogs.sap.com/2017/01/16/sap-hcp-is-exception-sub-process-how-to-create-alert-body-for-error-notification/ 12/20
1/28/2020 [SAP HCP-IS ]Exception Sub Process-How to create Alert body for Error Notification | SAP Blogs

Sriprasad Shivaram Bhat | Post author

March 2, 2017 at 6:00 pm

Hello Hari,

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

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.io.*;

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


message.setProperty("P_Tenant_Name",TMN_ShortName);

return message;
}

Regards,

Sriprasad Shivaram Bhat

https://blogs.sap.com/2017/01/16/sap-hcp-is-exception-sub-process-how-to-create-alert-body-for-error-notification/ 13/20
1/28/2020 [SAP HCP-IS ]Exception Sub Process-How to create Alert body for Error Notification | SAP Blogs

Like (0)

Former Member

March 22, 2017 at 8:53 pm

Sri,  this was very informative and cleared up some of my questions.

regards,

Christian Caldwell

Like (0)

Former Member

June 1, 2017 at 4:17 pm

Is there any way to set a cadence to when these alerts are sent?  We have a ow 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 noti ed the rst couple times that there is an issue.

Thanks,

https://blogs.sap.com/2017/01/16/sap-hcp-is-exception-sub-process-how-to-create-alert-body-for-error-notification/ 14/20
1/28/2020 [SAP HCP-IS ]Exception Sub Process-How to create Alert body for Error Notification | SAP Blogs

Kenny

Like (0)

Sriprasad Shivaram Bhat | Post author

June 1, 2017 at 5:23 pm

Yes you can do it with some more extra e orts:(,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 ow 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.

Regards,

Sriprasad Shivaram  Bhat

Like (0)

Former Member

June 1, 2017 at 11:34 pm

Thank you very much for your quick reply.

Like (0)

Devaraj R

June 9, 2017 at 7:53 pm

Hi Sriprasad,

https://blogs.sap.com/2017/01/16/sap-hcp-is-exception-sub-process-how-to-create-alert-body-for-error-notification/ 15/20
1/28/2020 [SAP HCP-IS ]Exception Sub Process-How to create Alert body for Error Notification | SAP Blogs

This solution is ne 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 noti cation to be triggered immediately for each message failure which is
occurring in our tenant for all these integrations.

It’s di cult to con gure this Exceptional sub process in all our integrations.

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

Regards,

Deva

Like (0)

Sriprasad Shivaram Bhat | Post author

June 9, 2017 at 9:48 pm

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 ow with above steps and save it as Template.Later for other integration,template with error handling steps would be starting point.

Regards,

Sriprasad S Bhat

Like (0)

Devaraj R

https://blogs.sap.com/2017/01/16/sap-hcp-is-exception-sub-process-how-to-create-alert-body-for-error-notification/ 16/20
1/28/2020 [SAP HCP-IS ]Exception Sub Process-How to create Alert body for Error Notification | SAP Blogs

June 10, 2017 at 7:26 pm

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 clari cation: 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.?

Regards,

Deva

Like (0)

Sriprasad Shivaram Bhat | Post author

June 15, 2017 at 10:06 am

Hello Deva,

**How to deal with Save As Template. 

https://blogs.sap.com/2017/01/16/sap-hcp-is-exception-sub-process-how-to-create-alert-body-for-error-notification/ 17/20
1/28/2020 [SAP HCP-IS ]Exception Sub Process-How to create Alert body for Error Notification | SAP Blogs

I have written a blog on the same refer the same for more detail.

https://blogs.sap.com/2017/06/15/sap-cloud-platform-integration-creating-reusable-templates/

** But messages are showing as completed even if there is any exception/error.

By default in Exception Sub process End Message step will be there.From past 3 release onward behavior of the End Message step changed.End Message step
inside exception will set the Overall Message Status to Completed,if you want to set it as Failed please use Error End Event instead of End Message Event.

Regards,

Sriprasad Shivaram Bhat

Like (0)

Sidharth Mehta

October 6, 2017 at 7:48 am

Hi Sriprasad,

Exception Subprocess is not available in my i ow palette, do have any idea?

Please help.

https://blogs.sap.com/2017/01/16/sap-hcp-is-exception-sub-process-how-to-create-alert-body-for-error-notification/ 18/20
1/28/2020 [SAP HCP-IS ]Exception Sub Process-How to create Alert body for Error Notification | SAP Blogs

Regards,

Sidharth

Like (0)

Former Member

September 22, 2017 at 1:48 pm

Very Informative blog.

Can we send email noti cations to particular users only based on reading error records?

Like (0)

Amber Badam

October 18, 2017 at 1:08 pm

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 ?

Like (0)

Find us on

https://blogs.sap.com/2017/01/16/sap-hcp-is-exception-sub-process-how-to-create-alert-body-for-error-notification/ 19/20
1/28/2020 [SAP HCP-IS ]Exception Sub Process-How to create Alert body for Error Notification | SAP Blogs

Privacy Terms of Use

Legal Disclosure Copyright

Trademark Cookie Preferences

Newsletter Support

https://blogs.sap.com/2017/01/16/sap-hcp-is-exception-sub-process-how-to-create-alert-body-for-error-notification/ 20/20

Potrebbero piacerti anche