cancel
Showing results for 
Search instead for 
Did you mean: 

Sending an email based on a value in the payload

pi_consultant1
Participant
0 Kudos

Dear friends,

I've the following scenario:

Non-SAP to Non-SAP - synchronous

Based on a value in the field status I've to send an email to people responsible for this message flow and the message has to be processed succesfully.

We are using PI standalone Java so we dont have a ABAP Stack...


I think I have to use a UDF or is there another way to do it? If I have to use an UDF can you please provide me with the java code?


Thank you in advance,


Your help would be greatly appreciate it,


Kind regards,


John

Accepted Solutions (1)

Accepted Solutions (1)

former_member184720
Active Contributor
0 Kudos

Can you provide some more details about your scenario ?

Non-SAP to Non-SAP - synchronous

Is it synchronous? what is your sender protocol and receiver protocol?

Where &when do you want to send the email?

If you simply want to send emails from mapping, have a look at the below blogs -

Mail without email adapter? Part - I - Process Integration - SCN Wiki

pi_consultant1
Participant
0 Kudos

Hi Hareesh,

Thank you again for your quick reply

Yes my scenario is synchronous. My sender protocol is SOAP as well as my receiver protocol.

The sender system fills the below structure and when the status field is for example A, B, C I dont need to send an email and for all other statuses I have to send and email.

<?xml version="1.0" encoding="UTF-8"?>

<ns0:UpdateStatus xmlns:ns0="urn:update">

   <ns0:ID/>

   <ns0:STATUS/>

   <ns0:USER/>

   <ns0:VALIDATION/>

</ns0:UpdateStatus>

I dont know exactly what are the possibilities,

Can you please help me to the right direction?

Thank you very much,

Kind regards,

John

former_member184720
Active Contributor
0 Kudos

Hi John - Please follow the wiki which i shared earlier and then using a simple UDF, you can trigger email based on the status field..

pi_consultant1
Participant
0 Kudos

Hi Hareesh,

Thank you I tried that and get the same error as mentioned in this thread:

https://scn.sap.com/thread/1414931

The Function Library is well activated, but when I use it inside my mapping I get this error.


Do you have any idea what to do?


Kind regards,


John

former_member184720
Active Contributor
0 Kudos

Hi John - It should work. I've tested too.

I think you are not adding the Imported archive under the archives used section..

Former Member
0 Kudos

Hi

If you have solution manager for triggering alert, then the below approach will be the easiest solution.

1. You need to create one alert category in solman using transaction ALRTCATDEF.

2. Use the email group who will be receiving the alert email in the alert category.

Then inside the message mapping write an simple UDF who will take the status as the input.

If the status is not A,B,C then call the RFC  SALERT_CREATE using RFC look up in java.

Below are the sample code for calling the SALERT_CREATE in UDF

java.util.Map map;

try {

String msgid;

map = container.getTransformationParameters();

msgid = (String) map.get(StreamTransformationConstants.MESSAGE_ID);

Channel channel = LookupService.getChannel("XXXCLNT100","CC_RFC_R_PI");

RfcAccessor accessor = LookupService.getRfcAccessor(channel);

String rfcXML= "<ns0:SALERT_CREATE xmlns:ns0=\"urn:sap-com:document:sap:rfc:functions\">"+

      "<IP_ALIAS/>"+

      "<IP_APPLICATION_GUID/>"+

      "<IP_CAT>ALERT_TEST_UDF</IP_CAT>"+

      "<IP_XML_CONTAINER/>"+

      "<IT_CONTAINER>"+

         "<item>"+

            "<ELEMENT>ZCUSTOMER</ELEMENT>"+

            "<TAB_INDEX>0</TAB_INDEX>"+

            "<ELEMLENGTH>20</ELEMLENGTH>"+

            "<TYPE>C</TYPE>"+

            "<VALUE>"+pnum+"</VALUE>"+

         "</item>"+

             "</IT_CONTAINER>"+

    "</ns0:SALERT_CREATE>";

InputStream inputStream =new ByteArrayInputStream(rfcXML.getBytes());

XmlPayload payload = LookupService.getXmlPayload(inputStream);

Payload rfcOutPayload = accessor.call(payload);

return "";

}

catch(Exception e)

{

  throw new RuntimeException("Exception while checking for Distribution channel : "+e);

}

pi_consultant1
Participant
0 Kudos

Hi Hareesh,

Yes thank you  That was the problem...

I did fill the Archives Used under Function Library but apparently in the Message Mapping we have to fill it under tab function as well.

I have a problem to send an email now. I did fill these parameters:

I also can fill it in UDF as mentioned in the Wiki, I dont know If we have to fill both of them?

I guess mail server is also with smtp:// at the beginning but when I test it from Message Mapping test tab I dont see any emails in transaction SCOT.

SCOT is already configured and I get emails for other interfaces.

Can you help me with this?

Thank you in advance,

Kind regards,

John

pi_consultant1
Participant
0 Kudos

Hi Indrajit,

Thats a very interessting approach, but unfortunatly we dont use Solution Manager yet.

Thank you very much,

Kind regards,

John

former_member184720
Active Contributor
0 Kudos

Hi John - some thing wrong with your UDF.

No need to fill at both the places.. Don't supply them to UDF as parameters. You can hardcode in the code.. just replace them with the actual values...

email mail = new email();

mail.send("<mailhost>", "<to emailid>", "<subject>", "<content>", "<from emailid>");

also don't give the prefix "smtp".. remove it only supply your mailhost address.)eg. mail.yourcompany.com

pi_consultant1
Participant
0 Kudos

Hi Hareesh,

What is wrong with my UDF? This is how I define the Function Library and I call it from the message mapping. I change the values in the UDF and put the values hardcoded. Still without any result...

I can see the below traces when I test it from Operation Mapping:

Loaded class .FL_Mail
Loaded class mail.sdn.email

But have no idea why no mail is beind send... Is there any other trace or logging I can see? I tried NWA and standard logging but can't see anything.

Kind regards,

John

former_member184720
Active Contributor
0 Kudos

Hi John - All i can say is validate the supplied values. As i said earlier, just hard code the values in UDF and test the message mapping in ESR..

pi_consultant1
Participant
0 Kudos

Hi Hareesh,

I did the same and if you test it, it works, do you get an email? Or is there something wrong with the UDF/Java Class?

And how do you test it? I did this mapping to test it, so if I fill dummy, it should trigger an email, right? But still I dont see anything

former_member184720
Active Contributor
0 Kudos

Yes. I tested and it works.

I'm not doing any validation

I just mapped like below

source field -> UDF -> target field

pi_consultant1
Participant
0 Kudos

Strange!

Did you fill the same mail host as defined in transaction SCOT?

former_member184720
Active Contributor
0 Kudos

yes.. It's the same host..

Former Member
0 Kudos

Hi Hareesh,

did you solve this issue? may I ask how? I'm facing the exact same problem...

cheers,

Edu

Former Member
0 Kudos

Hi PI Consultant,

did you solve this issue? may I ask how? I'm facing the exact same problem...

Cheers,

Edu

Answers (2)

Answers (2)

roger_alluivall
Participant
0 Kudos

Hello John,

probably you tried it already, but why don't you configure two message mappings?

1.- One for the messages that have the status A, B or C

2.- One for the messages that have any other status. This last mapping should produce an xml similar to the following:

<ns:Mail xmlns:ns="http://sap.com/xi/XI/Mail/30">

  <Subject>Subject</Subject>

  <From>namea@company.com</From>

  <To>nameb@company.com</To>

  <Reply_To />

  <Content_Type>text/plain</Content_Type>

  <Content>

This is the content.

  </Content>

</ns:Mail>


In your ICO or Interface Determination you can create two conditions:

1.- One for the messages that have the status A, B or C

2.- One for the messages that have any other status.

And depending on the condition, you execute one mapping or another. Finally you can use a Soap Receiver Channel to send "normal" messages and the email adapter to send "error" messages.

Please, check the following links for further information:

Configuring the Receiver Mail Adapter (SAP Library - Partner Connectivity Kit)

XI/PI: Sending Emails Using XI Mail Adapter


I hope it helps!

Regards!

pi_consultant1
Participant
0 Kudos

Hi Roger,

The problem is that all of the messages have to be processed to the receiver system in the normal synchronous scenario and only when status A, B and C occures and email has to be send to some people and also these statuses have to be processed to the receiver system. So there are no error messages, just a notification mail has to be send for these statuses

So I gues I can't use another Message Mapping and Service Interface, right?

Kind regards,

John

roger_alluivall
Participant
0 Kudos

John,

Let me see if I understood correctly the scenario. You have synchronous messages from non-SAP system (sender) that have to be sent to a non-SAP system (receiver). Besides, whenever a message has status A, B or C, an email has to be sent to some people as well. Lets say you always send "normal" messages from sender to receiver and additionally emails to people when the status of the message has the statuses above. Right?

If so, why don't you use two different receivers? In your Receiver Determination you'll have a receiver without condition (so it always will receive messages) and the other one with condition status = A, B or C.

Then you'll have two interface determination, so you can use two different message mappings.

Best Regards!

pi_consultant1
Participant
0 Kudos

Hi Roger,

I did test it before as well, the problem is that this scenario is sunchronous. So I get the error: can't not split synchronous messages.

Any other idea?

Best regards,

John

roger_alluivall
Participant
0 Kudos

mmmm you are right. As I understand, BPM is not an option, is it? And to convert the interface from sync to async is neither an option, right?

Regards!

pi_consultant1
Participant
0 Kudos

Hi Roger,

No BPM is not an option, sync/async at the adapter side is allowd but not with BPM.

Regards,

John

Former Member
0 Kudos

Hello,

Use mail package and depending upon the status field value populate ur content (under content field in mail xsd) and send mail to user group.

>>I think I have to use a UDF or is there another way to do it? If I have to use an UDF can you please provide me with the java code?

What's ur logic and when exactly u want to send email?

Thanks

Amit Srivastava

pi_consultant1
Participant
0 Kudos

Hi Amit,

I have a synchronous scenario, I wanted to try that but the problem is how to embedd mail package into my synchronous scenario.

My sender and receiver systems are both Non-SAP and I use webservices for both sender and receiver to connect.

The sender system calls a synchronous webservice in PI and I cant use message splitting because its a synchronous scenario, right?

So what are the possibilities?

Thank you,

John

former_member184720
Active Contributor
0 Kudos

Hi John - I believe you can go with the java mapping (request/response) to trigger email. You can make use of the blogs i shared..

Former Member
0 Kudos

Hello John,

>>The sender system calls a synchronous webservice in PI and I cant use message splitting because its a synchronous scenario, right?

Yes, we cannot split messages in case of sync scenarios.

I think, u can check pointers provided above and try to send email messages at mapping level

In case u want to avoid using java udf/mapping, then gng with BPM is the other option - which is also not a bad solution in case u don't want to create java code.

Thanks

Amit Srivastava