{tocify} $title={Table of Contents}
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
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?
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.
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(
To get the ISA/GS header values in map, first we need to understand the output generated by Decode_X12_message component
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.
Below is EDI X12 850 test input posted using ARC to logic app
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
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
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)
Map between EDI X12 850 and Destination schema (XML_Orders_WithHeaders)
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
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
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.
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
So now we need to pass the values to the parameters, against SenderId -- ISA06 , ControlNumber -- ISA13 and for Code -- GS01
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
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
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
- How to configure Logic App Standard workflow behind Azure APIM
- How to Query Azure Table storage from Logic App | How to filter results of Azure Table storage from Logic App
- Understanding expressions in Logic Apps | Frequently used expressions in Logic Apps | What is expressions in Logic App
- How to use Logic app Run History | How to troubleshoot Logic App workflow execution
- Logic App and Slack - Sending messages to slack channel | Logic app and slack integration | Connecting Logic App to Slack channel
- How to access Application settings fields value from Logic app Standard workflow | Using Application settings as configuration store for Logic app standard workflow
- Developing Logic app standard workflow which uses Map locally and deploying to Azure
- Developing Logic App Standard Workflow Using Visual Studio Code | Create Logic App Standard Workflow Using Visual Studio Code
- Logic App - Xml to Json using Liquid Map | Append in Liquid Map
- How to use Azure Event Grid Custom Topic | Publishing and Subscribing from Azure Event Grid Custom Topic using Logic App
- Using Azure Storage Account Table as Config Store for Logic Apps | How to read and write from Logic App to Azure Storage Account Table
- Get Logic App Name in Logic App
- Difference between Logic App Consumption and Logic App Standard
- Getting Started with Logic App Standard | Overview of Logic App Standard | Basics of Logic App Standard
- How to find count of Logic App executions using Azure Portal
- Azure Functions vs Azure Logic App | Difference between Azure Functions and Azure Logic App
- Getting started with Logic App : Liquid Map | Using Liquid template in Logic app
- How to get actual error message of Scope in Logic App | Exception Handling in Logic app
- Interview questions and answers on Logic Apps | Interview questions for azure logic app developers
- How to execute Stored Procedure in Logic App | How to connect to SQL in Logic App
- How to get current date in logic app | How to format date time in Logic App
- BizTalk Developer getting started with Logic App
- Getting Started with Logic Apps - Fundamentals
- Getting Started with Logic Apps - Enterprise Application Integration
- Getting Started with Logic Apps - AS2
- Getting Started with Logic Apps - EDI X12 Fundamentals
- Getting Started with Logic Apps - XML to EDI X12
- Getting Started with Logic Apps - EDI X12 to XML
- Getting Started with Logic Apps - What happened to the Request?
- Inserting Multiple Records In On Prem SQL Using Logic App
- Inserting data in On Premises SQL Database using Logic Apps
- Installing and Configuring On Premises Data Gateway - By adding user to Active Directory
- XML Batching(Aggregation) in Logic App
- Batching(Aggregating) messages in Logic App
- Debatching(Splitting) JSON Message in Logic Apps - ForEach and SplitOn
- Debatching(Splitting) XML Message in Logic Apps - ForEach and SplitOn
- Securing Logic App with Azure Active Directory authentication
- Removing ns0: prefix from xml output from BizTalk/Logic app XSLT map
- Using Managed Identity in Logic Apps for Calling Active Directory Secured Function App
- Logic Apps : Fetching ISA and GS Segment Values From Interchange Envelope and Mapping
- Logic Apps : For Each Inside a For Each - Fetching values from field in an array inside an array
- How to configure Logic App Standard workflow behind Azure APIM
- How to Query Azure Table storage from Logic App | How to filter results of Azure Table storage from Logic App
- Understanding expressions in Logic Apps | Frequently used expressions in Logic Apps | What is expressions in Logic App
- How to use Logic app Run History | How to troubleshoot Logic App workflow execution
- Logic App and Slack - Sending messages to slack channel | Logic app and slack integration | Connecting Logic App to Slack channel
- How to access Application settings fields value from Logic app Standard workflow | Using Application settings as configuration store for Logic app standard workflow
- Developing Logic app standard workflow which uses Map locally and deploying to Azure
- Developing Logic App Standard Workflow Using Visual Studio Code | Create Logic App Standard Workflow Using Visual Studio Code
- Logic App - Xml to Json using Liquid Map | Append in Liquid Map
- How to use Azure Event Grid Custom Topic | Publishing and Subscribing from Azure Event Grid Custom Topic using Logic App
- Using Azure Storage Account Table as Config Store for Logic Apps | How to read and write from Logic App to Azure Storage Account Table
- Get Logic App Name in Logic App
- Difference between Logic App Consumption and Logic App Standard
- Getting Started with Logic App Standard | Overview of Logic App Standard | Basics of Logic App Standard
- How to find count of Logic App executions using Azure Portal
- Azure Functions vs Azure Logic App | Difference between Azure Functions and Azure Logic App
- Getting started with Logic App : Liquid Map | Using Liquid template in Logic app
- How to get actual error message of Scope in Logic App | Exception Handling in Logic app
- Interview questions and answers on Logic Apps | Interview questions for azure logic app developers
- How to execute Stored Procedure in Logic App | How to connect to SQL in Logic App
- How to get current date in logic app | How to format date time in Logic App
- BizTalk Developer getting started with Logic App
- Getting Started with Logic Apps - Fundamentals
- Getting Started with Logic Apps - Enterprise Application Integration
- Getting Started with Logic Apps - AS2
- Getting Started with Logic Apps - EDI X12 Fundamentals
- Getting Started with Logic Apps - XML to EDI X12
- Getting Started with Logic Apps - EDI X12 to XML
- Getting Started with Logic Apps - What happened to the Request?
- Inserting Multiple Records In On Prem SQL Using Logic App
- Inserting data in On Premises SQL Database using Logic Apps
- Installing and Configuring On Premises Data Gateway - By adding user to Active Directory
- XML Batching(Aggregation) in Logic App
- Batching(Aggregating) messages in Logic App
- Debatching(Splitting) JSON Message in Logic Apps - ForEach and SplitOn
- Debatching(Splitting) XML Message in Logic Apps - ForEach and SplitOn
- Securing Logic App with Azure Active Directory authentication
- Removing ns0: prefix from xml output from BizTalk/Logic app XSLT map
- Using Managed Identity in Logic Apps for Calling Active Directory Secured Function App
- Logic Apps : Fetching ISA and GS Segment Values From Interchange Envelope and Mapping
- Logic Apps : For Each Inside a For Each - Fetching values from field in an array inside an array