Customize E-Mail Body and Subject in Alerts in SAP PI 7.31 – Java Stack Only – Part 1 – ESR
We can raise an alert in SAP PI 7.31 by scheduling AlertConsumerJob for a particular Consumer (Default given by SAP is ALERT-TO-MAIL) using a Java Mail client. After setting up Java mail client we can send an alert email to the defined consumer of AlertConsumerJob.
The mail content and subject sent to the consumer (Recipients) is in very unreadable format. Below is the screenshot of the message sent when an alert get consumed.
Understanding of this message is quite difficult to a person who is not having technical background or rather PI background. Alert email body and subject line is not much of relevance if we raise an alert through alert scheduler job in standard way.
SAP has also provided some of the standard webservices and operations which we can use to customize this solution. With the help of these standard webservices we can create a scenario in SAP PI and raise an alert for each error. Have a look into below screenshot for interfaces provided by SAP for this purpose.
These are the namespaces where above service interfaces reside. We will use above service interfaces to create customized alert scenario.
Solution scenario is like File – Synchronous SOAP Call – Mail.
First work is to add an entry of Basis SWCV into underlying Software Component Version in our SWCV, and then only we will be able to use objects of other namespace. I assume all SLD settings are done.
I will use below message types from SAP Basis 7.31 SWC.
We will copy above message types into our SWCV. For this purpose, I have created below name space and message types. I am not explaining in detail about how to create name spaces data types and message types. Also, from below screenshot you can see
Outbound Message type structure MT_Alert_Struct_Out, which is similar to RetrieveSingleAlertsRequest of Basis SWCV. Have a look.
Inbound Message Type Structure MT_Alert_Struct_In structure is of output structure in which we will raise an alert.
Define service interfaces like below screenshots.
OutBound – Synchronous
Inbound Synchronous – in this service interface we have used standard message types provided in SAP Basis SWC.
Now next step is to create 2 message mapping. Create Mappings as per below screenshot.
Below mapping is simple one to one mapping in the request mapping.
Response mapping contains the parsing logic. And how do we map from source values to target values. Response values in this case will come from one of the standard webservices hosted in service registry.
Once we get response from webservice, it populates values into AlertPayload of RetrieveSingleAlertsResponse. AlertPayload receives values in below format –
To populate these values into target fields we will require doing conversions or writing UDF’s to parse above values. Below is the screenshot, about how I am parsing above values. It can be changed depending upon the logic of a person.
Note – I have mentioned an UDF under red square.
In above graphical mapping, Component in red circle is an UDF. Below is the UDF code we can reuse below code for other output fields too. I am showing UDF for one the component. In the below code, you just need to change the value of this line
if(value.equals(“AdapterType”)). In case, if you want to code for MsgID – you have to use like –
if(value.equals(“MsgID”)) and use the same graphical mapping as shown above.
String result = “”;
String value = “”;
String actual = “”;
int flag = 0;
int count = 0;
int qtnum = 0;
if(AlertPayload.length() != 0)
for(int i =0;i<AlertPayload.length();i++)
if(count == 3)
if(AlertPayload.charAt(i) != ‘”‘)
actual = actual + AlertPayload.charAt(i);
result = actual; flag = 0; count = 0;
flag = 0; count = 0; value = “”;
else if(flag ==1 && count != 3)
if(AlertPayload.charAt(i) != ‘”‘ && qtnum != 4)
value = value + AlertPayload.charAt(i);
flag = 0; count = count +1; qtnum = qtnum + 1;
if (qtnum == 5)
qtnum = 0;count = 0;
else if(AlertPayload.charAt(i) == ‘”‘)
flag = 1;
count = count +1;
qtnum = qtnum + 1;
//result = value;
Create Operations mapping to complete ESR part as below screenshot.
Operations Mapping – Request
Operations Mapping – Response
We are done with ESR developments. Activate it.
Second part will contain actual configuration of this scenario.
Second part link – Customize E-Mail Body and Subject in Alerts in SAP PI 7.31 – Java Stack Only – Part 2 – ID
Nice Blog Aashis..
I want to do very similar customization in PI 7.30 dual stack. Will that be possible? Plus I also want to schedule job to alert mails only during business hours. Do you have any input for 7.3 version?
I think all these Alert API's should work in SAP PI 7.30 as well. You just need to check below things -
1. Check out for Alert API's available in WSNavigator
2. Check out for Message Types and Service Interface are available for Alert API's as suggested above in SAP Basis component.
3. You can run your sender File channel to pick the files from server to execute further with channel scheduling as per business requirement. This whole scenario works on input file.
I have written one blog which deals with additional attributes from payload so that functional/business teams can check key attributes in alert.
Enhancing CBMA Alerts and Message Monitoring with UDS Attributes
As the alternative, you can write simplest scenarion: JMS Sender channel with topic connection factory to jmsfactory/alertingVP/QueueConnectionFactory, queue jmsqueues/alertingVP/jms/queue/xi/monitoring/alert/ALERT-TO-MAIL and context com.sap.engine.services.jndi.InitialContextFactoryImpl (endpoint is localhost:5xx04).
Hi Michael ,
The UDF used in mapping for conversion of alert PAyload to XML will remain same for other fields . Apart from the String value change in the UDF, Any change in logic is req. ?
No, Not required !!
I have used the same configuration for asynchronous interface. It was working fine. But for synchronous interfaces it is not working. No alert is been generated.
Actually using the same ESR and in ID creating one more ICO for synchronous interface with a separate consumer.
Appreciate your help in this.
Thanks for sharing the blog.
we want the same concept of triggering alert messages to an email where I have PI 7.3 dual stack.
how can we do this? Any idea? Thanks in Adv.
I have done the similar configuration in PI 7.4. In the ID part, you mentioned about the file sender channel. Where this should point to ? This should point to the files which i have to process or the alerts ? If alerts - where the alerts will be located as a file?