Skip to Content
0

Read mail attachment in message mapping using UDF,giving error.

Nov 01, 2016 at 09:59 AM

125

avatar image

Hello Experts,

I am working on a scenario where PI has to read mail and its attachment and send this data to ECC.

Reading mail content is easy but challenge is while trying to read content of the attachment .

I am referring these posts https://archive.sap.com/discussions/thread/1341089 and https://blogs.sap.com/2009/08/23/read-the-attachments-of-the-input-xi-message-in-the-message-mapping/

The attachment that I have is an excel file which I am planning to send ECC in a field .Now I expect some problem here since this would require me to first convert the excel into a format which could be set in a string field.At ECC end they would again convert the content back to its earlier form.

Problem as of now is that the whole excel (I even tried text file as an attachment) goes to the target field but it only yeilds some garbage value of size 5 or 7 char ex "5@dskjhjd" that's it .Where as I am expecting it to be too long since it has the whole content of the attachment.

Any help is appreciated.

Code I am using in UDF is below:

String Content = ""; String AttachmentID =""; GlobalContainer globalContainer = container.getGlobalContainer(); InputAttachments inputAttachments = globalContainer.getInputAttachments(); if(inputAttachments.areAttachmentsAvailable()) { Collection<String> CollectionIDs = inputAttachments.getAllContentIds(true); Object[] arrayObj = CollectionIDs.toArray(); int attachmentCount = arrayObj.length; for(int i =0;i<attachmentCount;i++) { AttachmentID = (String)arrayObj[i]; Attachment attachments =inputAttachments.getAttachment(AttachmentID); Content = Content + attachments.getContent().toString(); } }return Content;

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

avatar image
Former Member Nov 01, 2016 at 10:14 AM
0

Hi Dilip,

The below statement toString method returns object id not the content because getContent() method returns byte array.

Content = Content + attachments.getContent().toString(); 

You need to change the statement to below.

Content = Content + new String(attachments.getContent());

Regards,

Praveen.

Share
10 |10000 characters needed characters left characters exceeded