{tocify} $title={Table of Contents}
This article intends to show how to fetch the individual UNB and UNG segment values using helper class and mapping those to the destination structure.
Many times there is required to pass or store the values from UNB (Interchange Control Header) and UNG (Functional group) segments. But this is not part of the data and not all properties from Envelope are promoted or written in the context of the message. Segments have data elements which are separated by element separator, also sub data elements which are separated by subelement separator.
In the input sample shown below "+" is the element separator, ":" is the subelement separator and "'" is the segment separator.
Make this independent project so that it can be used wherever required without any dependency.
Introduction
To accept/process an EDIFACT message in BizTalk, EDI Receive Pipeline is used and in it the actual data (message -- UNH to UNT) is extracted after detaching envelope part (header and trailer) and added to message context. Only few UNB and UNG segments are promoted, whereas UNB_Segment and UNG_Segment are written, rest properties are not promoted due to performance reason.This article intends to show how to fetch the individual UNB and UNG segment values using helper class and mapping those to the destination structure.
Scenario
For this walkthrough have considered to use EDIFACT INVOIC which are received and data from it has to be mapped to the destination structure, also Interchange Control and Functional Group Header values. Destination structure can be XML, Flat file or schema generated from database. For this post, destination structure is XML Canonical Invoice.Input
EDIFACT messages are wrapped with envelope, at header it has UNB segment (Interchange control header - Mandatory), UNG (Functional group - Conditional) and UNH (Transaction Set) and at the trailer it has UNZ, UNE and UNT. Enveloping segments work in pairs. UNB-UNZ represents an interchange. UNG-UNE is a functional group inside of the interchange and UNH-UNT is a transaction inside the group.Many times there is required to pass or store the values from UNB (Interchange Control Header) and UNG (Functional group) segments. But this is not part of the data and not all properties from Envelope are promoted or written in the context of the message. Segments have data elements which are separated by element separator, also sub data elements which are separated by subelement separator.
In the input sample shown below "+" is the element separator, ":" is the subelement separator and "'" is the segment separator.
How To Do
Step 1: Helper class which will split the segment and return individual value
- Create a C# class library project (EDIFACTSegmentValueFetcher Helper class)
- Sign and Build the project.
- Add it to GAC.
Make this independent project so that it can be used wherever required without any dependency.
Step 2: Create BizTalk Project
- Add EDIFACT INVOIC schema (EDI schema is shipped in as a self-extracting executable and when extracted, schemas can be found at drive:\Program Files\Microsoft BizTalkServer2010\XSD_Schema\EDI).
- Add/Create Output schema CanInvoice as shown below.
Step 3: Context Schema which will hold the UNB,UNG,ElementSeparator and SubelementSeparator
- Add a schema to project (InterchangeContext).
- Add four elements of type string
- UNBSegment
- UNGSegment
- ElementSeparator
- SubElementSeparator
- Make all four elements as Distinguished field.
Step 4: Add references
- EDIFACTSegmentValueFetcher.dll (Helper class) : This will help in using the method to split the segment and return individual values.
- Microsoft.BizTalk.Edi.BaseArtifacts.dll : This will help in accessing the EDIContext properties in Orchestration.
Note: EDIFACTSegmentValueFetcher is created as an independent project so that it can be used with other projects wherever required.
Step 5 : Create Orchestration
Covered in next post : BizTalk Server : Fetching UNB and UNG Segment Values From Interchange Envelope and Mapping - Orchestration
Download Sample
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 !!!!!!
Hi Maheshkumar,
ReplyDeleteTHe links to the download samples are not valid anymore. Could you please provide EDIFACTSegmentValueFetcher.dll?
Thank you!