You are on page 1of 11

Process Integration (PI) & SOA Middleware:

Creating File Name from Mail Attachment


using Standard Beans
Posted by sivasakthi danasekaran Apr 2, 2013
Business Driver Purchase and Sales information is sent from a partner via Email as a CSV attachment. PI has
to poll the Email server, retrieve these mails and write the CSV files in PI server directory with exactly the same
name as the mail attachment. Solution This requirement has popped up many times in the sdn
forums
and the solution to this currently is to deploy a custom adapter modulehttp://wiki.sdn.sap.com/
wiki/display/XI/Adapter+Module+PI+7.0+Get+Attachment+Name But the same requirement
can be sufficed with absolutely no coding or creation of adapter modules. This can be achieved
with 3 standard beans: MultipartHeaderBean ,PayloadSwapBean and DynamicConfigurationBean
In this blog I have highlighted only the specific settings that have to be maintained in the
communication channels to achieve our requirement, all the other ESR & ID objects should be
created as usual. Sender Email Channel Settings In the sender email communication channel make
sure to check the Keep Attachments option , which is required to retain the attachment.
Also check the Set Adapter-Specific Message Attributes option to enable the Dynamic
Configuration attributes to be available. Pic 1.1

Pic 1.2

Generated by Jive on 2014-12-02+01:00


1

Process Integration (PI) & SOA Middleware: Creating File Name from Mail Attachment using Standard Beans

The MultipartHeaderBean enables us to access the attributes of other payloads that are
appended to the XI message as
an additional attachment. In the Module tab add the MultipartHeaderBean with the following
parameters:
Parameter Name

Parameter Value

requiredHeaders

All

dcNamespace

http://sap.com/xi/XI/System/Mail

Using the PayloadSwapBean here we can replace the application payload of the XI message
i.e. email content, with another payload that is appended to the XI message i.e. the attachment
Add the PayloadSwapBean with the following parameters:
Parameter Name

Parameter Value

swap.keyName

Payload-Name

swap.keyValue

MailAttachment-1

Pic 1.3

Generated by Jive on 2014-12-02+01:00


2

Process Integration (PI) & SOA Middleware: Creating File Name from Mail Attachment using Standard Beans

Receiver File Channel Settings


Now in the Receiver File adapter we are going to use the DynamicConfigurationBean to retrieve the
attachment name.
The attachment file name is available in the Dynamic configuration attribute Part[1].Content-Description, which
we will write to the PI message interface name.

To the 'Module' tab add the DynamicConfigurationBean with the following parameters:
Parameter Name

Parameter Value

key.0

write http://sap.com/xi/XI/System/Mail
Part[1].Content-Description

value.0

message.interface

Pic 2.1

Generated by Jive on 2014-12-02+01:00


3

Process Integration (PI) & SOA Middleware: Creating File Name from Mail Attachment using Standard Beans

Using Variable Substitution, create a variable fname referencing the message interface name and access this
variable in the file name field.
Pic 2.2

Generated by Jive on 2014-12-02+01:00


4

Process Integration (PI) & SOA Middleware: Creating File Name from Mail Attachment using Standard Beans

Pic 2.3

Testing

Generated by Jive on 2014-12-02+01:00


5

Process Integration (PI) & SOA Middleware: Creating File Name from Mail Attachment using Standard Beans

The configurations are complete. Its time to test our scenario.


A sample mail is sent to the mail account which the sender email adapter is polling with the attachment name
MyAttachment1.CSV
Pic 3.1

Integrated configuration was used in this scenario, so we can see the Dynamic Configuration message
attributes in message monitoring.
Note that Part[1].Content-Description has been set to MyAttachment1.CSV at runtime.
Pic 3.2

Generated by Jive on 2014-12-02+01:00


6

Process Integration (PI) & SOA Middleware: Creating File Name from Mail Attachment using Standard Beans

The payload was swapped successfully and the attachment data has been set to the main payload as shown
below.
Pic 3.3

Generated by Jive on 2014-12-02+01:00


7

Process Integration (PI) & SOA Middleware: Creating File Name from Mail Attachment using Standard Beans

We can see the output file in the output folder path with the same name as our attachment
MyAttachment1.CSV.

2219 Views Tags: integration


Elmar Fritz in response to Deepak Ravi on page 9
Dec 1, 2014 1:58 PM
Hello!
I tried to implement this, but it always fails with this error ...

SOAPFault empfangen vom Integration Server. ErrorCode/Category: XIProtocol/WRONG_VALUE;


Params: SOAP:Envelope(1)SOAP:Header(1)sap:DynamicConfiguration(3)sap:Record(2), attachment;
filename="=?iso-8859-1?Q?Preisliste=5FZertifizierungsgeb=C3=BChren=5Fbrutto=5Fnetto?
==?iso-8859-1?Q?=5F2014.pdf?="; size=27653;creation-date="Tue, 08 Jul 2014 13:32:58
GMT";modification-date="Tue, 08 Jul 2014 13:32:58 GMT", ST: ST_XMS_MSGHDR30_DYNAMIC;
AdditionalText: An error occurred when deserializing in the simple transformation program
ST_XMS_MSGHDR30_DYNAMIC; ApplicationFaultMessage: null; ErrorStack: XML
tag SOAP:Envelope(1)SOAP:Header(1)sap:DynamicConfiguration(3)sap:Record(2)
(or one of the attributes) has incorrect value attachment; filename="=?iso-8859-1?Q?
Preisliste=5FZertifizierungsgeb=C3=BChren=5Fbrutto=5Fnetto?==?iso-8859-1?Q?=5F2014.pdf?
="; size=27653;creation-date="Tue, 08 Jul 2014 13:32:58 GMT";modification-date="Tue, 08 Jul
2014 13:32:58 GMT" An error occurred when deserializing in the simple transformation program
ST_XMS_MSGHDR30_DYNAMIC Data loss occurred when converting attachment; filename="=?iso-8859-1?
Q?Preisliste=5FZertifizierungsgeb=C3=BChren=5Fbrutto=5Fnetto?==?iso-8859-1?Q?=5F2014.pdf?=";
size=27653;creation-date="Tue, 08 Jul 2014 13:32:58 GMT";modification-date="Tue, 08 Jul 2014 13:32:58
GMT"

Generated by Jive on 2014-12-02+01:00


8

Process Integration (PI) & SOA Middleware: Creating File Name from Mail Attachment using Standard Beans

Rams G in response to sivasakthi danasekaran on page 11


Oct 21, 2014 10:02 AM
Hi Sivasakthi,
Is it possible to pick the .PDF files from Emails and place them on FTP server with the same file name?
thanksRamesh
Deepak Ravi
Sep 18, 2014 3:16 PM
Hi Sivasakthi,
Your blog helpmed me a lot in creating the same with SOAP attachments.
Everything worked fine, except the file name generation. In dynamic configuration the file name is coming as
<filename.ext>. As '<' and '>' are not permitted in creation of file name, PI is generating it with underscores
(_filename.ext_).

Generated by Jive on 2014-12-02+01:00


9

Process Integration (PI) & SOA Middleware: Creating File Name from Mail Attachment using Standard Beans

I rectified this issue by using an UDF. But just want to know is there any other way to get the correct file name
in adapter level.
Regards,
Deepak Ravi
divyesh vasani
Mar 19, 2014 7:06 AM
Nice Blog
Very well explained... I like the use of MultiPartHeaderBean ...
--Divyesh
mastan vali
Jan 10, 2014 9:03 AM
Hi Siva,
thank you for letting us the standard beans for mail attachement.

Keep blogging
Regards,
Mastan
Monikandan Panneerselvam
Jan 10, 2014 8:55 AM
Nice blog siva
One clarification:
If it is FTP folder instead of NFS any specific change need to do or only the adapter selection is enough.
dhinesh kumar raj kumar

Generated by Jive on 2014-12-02+01:00


10

Process Integration (PI) & SOA Middleware: Creating File Name from Mail Attachment using Standard Beans

Jun 7, 2013 1:57 PM


Hi Sivasakthi,
I am working on a file to mail scenario in which i have to send the files as attachment with the same name of
the source file i am sending...but, the received mails are not having the same names for the attachments..My
requirement is to set these names to the attachments dynamically..I am a fresher to PI..can you please help
me to resolve my issue
sivasakthi danasekaran in response to Inder G on page 11
Apr 22, 2013 11:31 AM
Thnx
Francis Antony
Apr 18, 2013 1:03 PM
Good one.
Inder G
Apr 11, 2013 6:00 PM
Nice Blog Shakku

- Kulwinder

amarnath kashinath
Apr 2, 2013 9:33 PM
Nice Blog sivasakthi. Got to learn few things about mail adapter with attachments.
Thanks for sharing:)

Generated by Jive on 2014-12-02+01:00


11