Sending an email after EDI Inbound processing

Mirjana's picture
Request:
 
Send an email after EDI Inbound processing. Translated document must be sent as an attachment, and mail body should contain some static text/message or text dynamicaly created from envelopes included in that current processing (information can be gotten from the Process Data).
 
This piece of code, for sending an email, can be added in any process. In the case of EDI we will add specific data into body of mail, such as Sender ID, Receiver ID and Control Number.
 
Code can be added in the end of the business process (EDIInboundFileSystemExtraction) defined in UNH/UNT (EDIFACT) or ST/SE inbound envelope (X12):
 
 
 
EDIInboundFileSystemExtraction system process is used for this example and modified with services added for mail sending. Services are added in the very end of the BP.
This is just for test purposes.
 
Note: it is NOT recommended to make changes in system processes. It is better to use a custom process that will be run after deenveloping and translation. With patch installation, the system processes are overriden by new ones. 
Even if you make modifications on system processes, take it into consideration after upgrade, and move your custom versions of system processes back. Also, if any change is done by developers that come by a new patch, you will not get it, after you import your custom versions of system process.
 
Services for preparing and sending mail:
 
 
Assign element: used to move result of translation, that is normally under Primary Document, into a document with a different name. It is done because Mail Mime Service can take all the documents, with names different than PrimaryDocument, into attachment, and Primary Document is taken for a body of the mail.
 
<assign name="Assign" to="PrimaryDocument_forAttachment" from="PrimaryDocument/@SCIObjectID"></assign>
 
XSLT service: used to create an email body message with info from the Process Data. Result of XSLT Service will be in the Primary Document.
 
Mail Mime Service: create a MIME message, with attachment(s), body, including sender, receipient and other details in the mail based on settings of the service.
In Mail Mime Service, if we have parametermail-mime-use-doc-area set to true, then all the documents with names different than 'PrimaryDocument' will be attached to the mail. If there are more than one non-Primary Document, I do not know the way to select only some of the documents for attachments, the only solution is to make Release of the documents we do not want to be attached prior to creating MIME message.
 
SMTP Send Adapter: send an email. If it is preceeded by Mail Mime Service, like in this example, b2b-raw-message must be set to true, as SMTP Send Adapter get full MIME message. Also xport-smtp-mailhost and xport-smtp-mailport must be set.
 
BPML code:
 
Here is an example of bpml code and process for sending an email with attachment, for previously explained request.
Note: This is not a well formed XML/bpml as that is only a part of the full business process.
 
...
<assign name="Assign" to="PrimaryDocument_forAttachment" from="PrimaryDocument/@SCIObjectID"></assign>
 
    <operation name="XSLT Service">
      <participant name="XSLTService"/>
      <output message="XSLTServiceTypeInputMessage">
        <assign to="." from="*"></assign>
        <assign to="xslt_name">TEST_EDI_report</assign>
        <assign to="xml_input_from">ProcData</assign>
        <assign to="input_pd_xpath">/</assign>
      </output>
      <input message="inmsg">
        <assign to="." from="*"></assign>
      </input>
    </operation>
 
    <operation name="Mail Mime Service">
      <participant name="MailMimeService"/>
      <output message="MailMimeServiceInputMessage">
       <assign to="." from="*"></assign>
        <assign to="mail-mime-subject">EDI inbound - report</assign>
        <assign to="mail-mime-sender">[email protected]</assign>
        <assign to="mail-mime-operation">build</assign>
        <assign to="mail-mime-use-doc-area">true</assign>
        <assign to="mail-mime-recipient">[email protected]</assign>
        <assign to="mail-mime-body">true</assign>
      </output>
      <input message="inmsg">
        <assign to="." from="*"></assign>
      </input>
    </operation>
 
    <operation name="SMTP Send Adapter">
      <participant name="SMTP_SEND_ADAPTER"/>
      <output message="SMTP_SEND_ADAPTERInputMessage">
        <assign to="." from="*"></assign>
        <assign to="xport-smtp-mailhost">192.168.101.136</assign>
        <assign to="b2b-raw-message">true</assign>
        <assign to="xport-smtp-mailport">25</assign>
      </output>
      <input message="inmsg">
        <assign to="." from="*"></assign>
      </input>
    </operation>
...
 
Process Data:
 
Here is the Process Data after deenveloping and translation in EDI Inbound process has been done:
 
<?xml version="1.0" encoding="UTF-8"?>
<ProcessData>
         <PrimaryDocument SCIObjectID="mirjana:node1:12dd166c5f9:341799"/>
         <EnvelopeName>myUNH</EnvelopeName>
         <SegmentTerminator>39</SegmentTerminator>
         <elementForCC/>
         <InterchangeEnvelopeID>madrugada:699a1547:10a2a738628:-507e</InterchangeEnvelopeID>
         <TagSeparator>43</TagSeparator>
         <orderID>3830035970002-00000178</orderID>
         <MessageType>ORDERS</MessageType>
         <ComplianceCheckMapName>IE_EDIorders2inhouse</ComplianceCheckMapName>
         <InterchangeEnvelopeName>myUNB</InterchangeEnvelopeName>
         <ElementSeparator>43</ElementSeparator>
         <InterchangeRecipientID>3838551999996</InterchangeRecipientID>
         <ReleaseCharacter>63</ReleaseCharacter>
         <InterchangeTestIndicator>1</InterchangeTestIndicator>
         <EnvelopeID>madrugada:699a1547:10a3ae7370d:-72f6</EnvelopeID>
         <InterchangeControlNumber>100135</InterchangeControlNumber>
         <MessageReferenceNumber>5</MessageReferenceNumber>
         <InterchangeSenderID>3830035970002</InterchangeSenderID>
         <BAD_WFD_NAME>IE_nonCompliant_error_BP</BAD_WFD_NAME>
         <SubElementSeparator>58</SubElementSeparator>
</ProcessData>
 
OrderID, MessageType, InterchangeRecipientID, InterchangeControlNumber and InterchangeSenderID will be taken for creating mail body by using XSLT.
 
XSLT Service – for mail body:
 
This XSLT will create an email body message
 
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
         <xsl:output method="html" encoding="iso-8859-2" indent="yes"/>
         <xsl:template match="/">
                   <html>
                            <body>
                                      <b>EDI Report</b>
                                      <br/>
                                      <br/>
                                      <table>
                                               <tr>
                                                        <td>Order Id</td>
                                                        <td>
                                                                  <xsl:value-of select="//orderID/text()"/>
                                                        </td>
                                               </tr>
                                               <tr>
                                                        <td>Message Type</td>
                                                        <td>
                                                                 <xsl:value-of select="//MessageType/text()"/>
                                                        </td>
                                               </tr>
                                               <tr>
                                                        <td>InterchangeControlNumber</td>
                                                        <td>
                                                                  <xsl:value-of select="//InterchangeControlNumber/text()"/>
                                                        </td>
                                               </tr>
                                               <tr>
                                                        <td>InterchangeSenderID</td>
                                                        <td>
                                                                  <xsl:value-of select="//InterchangeSenderID/text()"/>
                                                        </td>
                                               </tr>
                                               <tr>
                                                        <td>InterchangeRecipientID</td>
                                                        <td>
                                                                  <xsl:value-of select="//InterchangeRecipientID/text()"/>
                                                        </td>
                                               </tr>
                                     </table>
                            </body>
                   </html>
         </xsl:template>
</xsl:stylesheet>
 
Mail gotten from the process:
 
 
You can find deenveloped and translated file in the attachment and result of XSLT translation in the body.
 
Change the attachment name:
 
Attachment has the default name given by EDI services, if you want to change it, you should set another name for the document that will be used for attachment. That can be done by Get Document Info Service, as the first step, so before assigning the PrimaryDocument into PrimaryDocument_forAttachment in the assign element.
 
 
 
Get Document Info service configuration:
 
<operation name="Get Document Information Service">
         <participant name="GetDocumentInfoService"/>
         <output message="GetDocumentInfoServiceTypeInputMessage">
                   <assign to="." from="*"/>
                   <assign to="BodyName">newAttachmentName</assign>
                   <assign to="updateMetaDataOnly">true</assign>
         </output>
         <input message="inmsg">
                   <assign to="." from="*"/>
         </input>
</operation>
 

Mail after setting a new Body Name for the document that will be attached to the mail: