on 03-15-2021 3:05 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.