Logic Apps : Fetching ISA and GS Segment Values From Interchange Envelope and Mapping | Azure Logic Apps EDI Implementation

{tocify} $title={Table of Contents}

Introduction


When we work with B2B using EDI standards in logic apps we use Decode component which does work of validation and decodes the EDI(flat file) and based on the settings we specify in Agreement, the Transaction sets are splitted (one edi document comprise of segments contained in ST to SE) and is available in Payload of Decode component for further use. 

EDI X12 messages are wrapped with envelope, at header it has ISA segment (Interchange control header), GS (Functional group) and ST (Transaction Set) and at the trailer it has IEA, GE and SE. Enveloping segments work in pairs. ISA-IEA represents an interchange. GS-GE is a functional group inside of the interchange and ST-SE is a transaction inside the group.

Most of the time, we need to map the individual edi documents(ST-SE) to destination system's expected format.

Read example about it -  Getting Started with Logic Apps - EDI X12 to XML where following map was used

EDI 850 to XML Order Map
If you see the destination schema gets all that it needs from the EDI document transaction set (segments between ST and SE).

What if destination system also want some info from Interchange headers or functional headers? But our Payload has only data segments and no Envelope segments. So how we do it?


Following are post which talk about how we did it in BizTalk

Now let's see how we do it in Logic Apps

Scenario


Say there is a company Techfindings and it wants to receive EDI X12 850 from its business partner and after getting it, it needs to convert it XML Purchase Order format which is expected by it's inhouse application for further processing.

EDI X12 850 files are received and data from it has to be mapped to the destination structure, also Interchange Control number, Interchange Sender ID and Functional Group Header Code values.

So we need to create a solution which will accept EDI X12 850 message and convert it to XML Purchase Order along with the Envelope (Interchange/functional header) values and forward it to Blob location for Inhouse application.

Steps in creating solution

    
    You can refer to previous blog  -  Getting Started with Logic Apps - EDI X12 to XML , which has same solution implemented and explained except for the new mapping  requirement  which I cover here.


   Destination schema with Interchange and Functional Header(XML_Orders_WithHeaders)


destination schema with headers


Map between EDI X12 850 and Destination schema (XML_Orders_WithHeaders)


map between EDI and destination schema with headers

If you see there is no mapping done for header nodes , it is because we don't have values needed for them in source schema.


Where to get Interchange and Functional Header values from


To get the ISA/GS header values in map, first we need to understand the output generated by Decode_X12_message component

Decode_X12_message Output

The output does has a Interchange/functional header values made available as a whole and as an individual elements apart from the actual data (Payload).

And this values can be accessed by any Action followed after Decode_X12_message action.


How to make this values available in Map



  Once mapping is done (step 2 above), we need to get the xslt file , for that right click on map file -->Select Debug and in output window you can see the xslt path

xslt path


  make note of path where xslt is stored,as it is this which is to be uploaded to integration account (.btm file is not supported). 
  


  Following is the xslt

<<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var s0" version="1.0" xmlns:ns0="http://EDIToXMLDemo.XML_Orders" xmlns:s0="http://schemas.microsoft.com/BizTalk/EDI/X12/2006">
  <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />
  <xsl:template match="/">
    <xsl:apply-templates select="/s0:X12_00504_850" />
  </xsl:template>
  <xsl:template match="/s0:X12_00504_850">
    <ns0:Orders>
      <Order>
        <Header>
          <PONumber>
            <xsl:value-of select="s0:BEG/BEG03/text()" />
          </PONumber>
          <PODate>
            <xsl:value-of select="s0:BEG/BEG05/text()" />
          </PODate>
        </Header>
        <xsl:for-each select="s0:PO1Loop1">
          <LineItems>
            <xsl:if test="s0:PO1/PO101">
              <ItemId>
                <xsl:value-of select="s0:PO1/PO101/text()" />
              </ItemId>
            </xsl:if>
            <xsl:if test="s0:PO1/PO102">
              <Quantity>
                <xsl:value-of select="s0:PO1/PO102/text()" />
              </Quantity>
            </xsl:if>
            <xsl:if test="s0:PO1/PO104">
              <UnitPrice>
                <xsl:value-of select="s0:PO1/PO104/text()" />
              </UnitPrice>
            </xsl:if>
            <xsl:if test="s0:PO1/PO107">
              <ItemDescription>
                <xsl:value-of select="s0:PO1/PO107/text()" />
              </ItemDescription>
            </xsl:if>
          </LineItems>
        </xsl:for-each>
      </Order>
    </ns0:Orders>
  </xsl:template>
</xsl:stylesheet>

  Now we make changes in above xslt to enable us to get the header values, and
for that we add parameters and assign them to respective nodes in destination
(marked in red)

<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var s0" version="1.0" xmlns:ns0="http://EDIToXMLDemo.XML_Orders" xmlns:s0="http://schemas.microsoft.com/BizTalk/EDI/X12/2006">
  <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />
  <xsl:param name="SenderId"/>
  <xsl:param name="ControlNumber"/>
  <xsl:param name="Code"/>
  <xsl:template match="/">
    <xsl:apply-templates select="/s0:X12_00504_850" />
  </xsl:template>
  <xsl:template match="/s0:X12_00504_850">
    <ns0:Orders>
      <Order>
        <Header>
          <PONumber>
            <xsl:value-of select="s0:BEG/BEG03/text()" />
          </PONumber>
          <PODate>
            <xsl:value-of select="s0:BEG/BEG05/text()" />
          </PODate>
        </Header>
        <xsl:for-each select="s0:PO1Loop1">
          <LineItems>
            <xsl:if test="s0:PO1/PO101">
              <ItemId>
                <xsl:value-of select="s0:PO1/PO101/text()" />
              </ItemId>
            </xsl:if>
            <xsl:if test="s0:PO1/PO102">
              <Quantity>
                <xsl:value-of select="s0:PO1/PO102/text()" />
              </Quantity>
            </xsl:if>
            <xsl:if test="s0:PO1/PO104">
              <UnitPrice>
                <xsl:value-of select="s0:PO1/PO104/text()" />
              </UnitPrice>
            </xsl:if>
            <xsl:if test="s0:PO1/PO107">
              <ItemDescription>
                <xsl:value-of select="s0:PO1/PO107/text()" />
              </ItemDescription>
            </xsl:if>
          </LineItems>
        </xsl:for-each>
      </Order>
  <InterchangeHeader>
        <ISA04>
          <xsl:value-of select="$SenderId" />
        </ISA04>
        <ISA13>
          <xsl:value-of select="$ControlNumber" />
        </ISA13>
      </InterchangeHeader>
      <FunctionalHeader>
        <GS01>
          <xsl:value-of select="$Code" />
        </GS01>
      </FunctionalHeader>
    </ns0:Orders>
  </xsl:template>

</xsl:stylesheet>


Save the modified xslt and upload it to integration account.

Go to the integration account created earlier in step1  and select the Maps tiles and click on add button. 
   Give name EDI850_toXMLOrderWithheaders and browse to xslt path(saved in step 3) and save.

Use above XSLT in Logic App 



In Transform XML action


Against content add following expression -- xml(base64ToBinary(item()?['Payload']))

Against map select EDI850_toXMLOrderWithheaders and as soon as you select it
Parameters which you added in xslt will be should diplayed
xslt parameter in logic app

So now we need to pass the values to the parameters, against SenderId -- ISA06 , ControlNumber -- ISA13 and for Code -- GS01

Passing values to parameter

That's it , we are done with all required to do in Transform XML, complete the logic app design and save it and let's test.




Testing


Below is EDI X12 850 test input posted using ARC to logic app



Test input

Logic app receives EDI 850 messager over http, then it Decodes EDI X12 message  and then  transforms it  in xml Order  with help of Transform XML action and finally places the converted file in blob container.

Below is xml file created in blob container and its content


final output




If you have questions or suggestions, feel free to do in comments section below !!!


Do share if you find this helpful .......
 
                        Knowledge Sharing is Caring !!!!!!





Learn More about Logic App

    Post a Comment

    If you have any suggestions or questions or want to share something then please drop a comment

    Previous Post Next Post