Skip to Content
Author's profile photo Aashish Sinha

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.

Pic1.jpg

    

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.

/wp-content/uploads/2012/10/pic2_149442.jpg

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.

ESR Developments

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.

/wp-content/uploads/2012/10/pic3_149443.jpg

I will use below message types from SAP Basis 7.31 SWC.

Pic4.jpg

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

/wp-content/uploads/2012/10/pic5_149445.jpg

Outbound Message type structure MT_Alert_Struct_Out, which is similar to RetrieveSingleAlertsRequest of Basis SWCV. Have a look.

/wp-content/uploads/2012/10/pic6_149446.jpg

Inbound Message Type Structure MT_Alert_Struct_In structure is of output structure in which we will raise an alert.

/wp-content/uploads/2012/10/pic7_149447.jpg

Define service interfaces like below screenshots.

OutBound – Synchronous

/wp-content/uploads/2012/10/pic8_149448.jpg

Inbound Synchronous – in this service interface we have used standard message types provided in SAP Basis SWC.

/wp-content/uploads/2012/10/pic9_149449.jpg

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.

/wp-content/uploads/2012/10/pic10_149453.jpg

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.

   /wp-content/uploads/2012/10/pic11_149454.jpg

Once we get response from webservice, it populates values into AlertPayload of RetrieveSingleAlertsResponse. AlertPayload receives values in below format –

/wp-content/uploads/2012/10/pic12_149455.jpg

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.

/wp-content/uploads/2012/10/pic13_149456.jpg

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.

UDF Code

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(value.equals(“AdapterType”))
{
    if(AlertPayload.charAt(i) != ‘”‘)
    {
      actual = actual + AlertPayload.charAt(i);
    }
    else
    {
      result = actual; flag = 0; count = 0;
      break;
    }
}
else
{
   flag = 0; count = 0; value = “”;
}
}
else if(flag ==1 && count != 3)
{
   if(AlertPayload.charAt(i) != ‘”‘ && qtnum != 4)
   {
     value = value + AlertPayload.charAt(i);
   }
   else
   {
     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;

return result;

Create Operations mapping to complete ESR part as below screenshot.

Operations Mapping – Request

/wp-content/uploads/2012/10/pic14_149457.jpg

Operations Mapping – Response

/wp-content/uploads/2012/10/pic15_149458.jpg

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

Assigned Tags

      9 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Nice Blog Aashis..

      Author's profile photo Baskar Gopalakrishnan
      Baskar Gopalakrishnan

      Hi 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?

      Author's profile photo Aashish Sinha
      Aashish Sinha
      Blog Post Author

      Hi Baskar,

      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

      Regards

      Aashish Sinha

      Author's profile photo Iliya Kuznetsov
      Iliya Kuznetsov

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

      Author's profile photo Former Member
      Former Member

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

      Author's profile photo Aashish Sinha
      Aashish Sinha
      Blog Post Author

      No, Not required !!

      Author's profile photo Farooq Ahmed
      Farooq Ahmed

      Hi Aashish,

      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.

      Thank You.

      Regards,

      Farooq

      Author's profile photo Murali Krishna Vankadoath
      Murali Krishna Vankadoath

      Hi Aashish,

       

      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.

       

      BR,

      Murali.

      Author's profile photo Former Member
      Former Member

      Hi Aashish

      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?