cancel
Showing results for 
Search instead for 
Did you mean: 

CPI - How to process Multiple PDF Attachments

kamranakhtar
Participant
0 Kudos

Hi,

I have a SAP CPI iFlow with Sender email and SOAP receiver.

Emails sent can have multiple PDF Attachments. I need a split for each PDF and pass it to the SOAP Call.

I have a Groovy Script which assigns the attachment to the Body. But how can I set this so it assigns all the attachments and I can then split according each PDF.

Thanks
Kamran

Accepted Solutions (0)

Answers (4)

Answers (4)

dan_dworak
Explorer
0 Kudos

Hi Kamran,

Did you ever get this working? I have a similar requirement to process an email with multiple attachments. Currently am getting similar behavior where the last attachment becomes the payload.

Thanks

kamranakhtar
Participant
0 Kudos

Hi Anil,

The SOAP call has attachment field and I am basically mapping it to the body of the message, as previous Groovy was assigning attachment to the body. Not sure why it is currently setting body of the email rather than the attachment as body. However I cant see how the iterator class is creating multiple message. It seems the last attachment sets the body. When I check in the Payload I can see the data for the last attachment only.

sumanth171
Active Participant
0 Kudos

The script will set the data as message body. I couldn't understand if you want to make these pdfs as attachment to SOAP call or as a message body. Also as I said, because of the iterator class a multiple messages with be generated for each attachment.

Regards,

Anil

sumanth171
Active Participant
0 Kudos

Hi Kamran,

Using Iterator class, you can get all attachments and set the body and I assume there won't be a splitter necessary for this as individual message creates for an attachment. Can you try with the code below.

import com.sap.gateway.ip.core.customdev.util.Message
import java.util.Map
import java.util.Iterator
import javax.activation.DataHandler

def Message processData(Message message) {
Map<String, DataHandler> attachments = message.getAttachments()
Iterator<DataHandler> it = attachments.values().iterator()
DataHandler attachment = it.next()
message.setBody(attachment.getContent())
return message
}

Regards,

Anil

kamranakhtar
Participant
0 Kudos

Hi Anil,

I had to modify the code to only allow PDF attachments as it had issues with image from email footer

def Message processData(Message message) {

Map<String, DataHandler> attachments = message.getAttachments()

Iterator<DataHandler> it = attachments.values().iterator() DataHandler attachment = it.next() if(attachment.getContentType().contains("pdf")){

message.setBody(attachment.getContent())

}

return message

}

However this seems to be bringing in the body rather than the attachments. And also I will need each attachment to be split and posted to S4HC via SOAP Call.