cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to drop/delete attachment(s) from CPI message

rajesh_baldha
Explorer
0 Kudos
1,119

Dear Experts,

We have a requirement in CPI where we have to send file attachment with SOAP request.

but after that attachment processing done we need to delete that attachment from message object, because it cause an error at next process step while I try to call SFDC SOAP service to upsert/create request.

Attachment is also going with SFDC call which must not be happened.

Even Router and Parallel Processing not working to drop attachment.

Can anyone please help here.

Thanks in Advance

Regards,

Rajesh

View Entire Topic
MortenWittrock
SAP Mentor
SAP Mentor
0 Kudos

Hi Rajesh

I've deleted my previous answer, which was almost correct 🙂 I had half of the solution, and the always brilliant ilya.stepanov had the other half. The following code works:

import com.sap.gateway.ip.core.customdev.util.Message

def Message processData(Message message) {
message.getAttachments().clear()
message.getAttachmentWrapperObjects().clear()
return message
}

My first solution only cleared the attachments Map (the first line of the processData method). This would work in Apache Camel, which is Cloud Integration's underlying integration framework. However, for it to work in Cloud Integration, there is a Map of attachment wrapper objects, which must be cleared as well. This happens in the second line.

Have fun with CPI!

Regards,

Morten

rajesh_baldha
Explorer
0 Kudos

Thanks Morten and Stepanov,

This is working perfectly fine. Problem has resolved now.

Thanks ,

Rajesh

MortenWittrock
SAP Mentor
SAP Mentor
0 Kudos

Hi rajesh_baldha

Glad to hear it!

Regards,

Morten

jayesh2203
Explorer
0 Kudos
Just to add, to ensure proper functionality, please ensure the use of the following three APIs to delete/remove attachments. I faced some issue when I used only 2 mentioned above. With below code it should work fine. KBA for the same. https://me.sap.com/notes/0003240138 message.getAttachments().clear() message.getAttachmentObjectss().clear() message.getAttachmentWrapperObjects().clear()