In my last BizTalk post, I showed a project that routed xml messages to different parties based on the destination party name. It worked for simple xml messages, but if you want to work with EDI files you need to set up actual trading partner agreements between the parties, in order to configure the additional information needed to send an EDI X12 message (the ISA & GS segments).
We'll build off the solution previously created by adding an X12 schema, mapping the xml purchase order to it, and create trading partner agreements to properly build the EDI messages.
To start, open the solution you created in the previous blog post and add the X12_004010_810.xsd (<BizTalk install directory>\XSD_Schema\EDI\X12\00401\X12_004010_810.xsd) schema to the project. We're going to delete a good chunk of the schema's segments, since we don't want to bother with all of the fields that are actually required. This might not be realistic in the real world, but it's fine for our demo scenario. Delete all of the segments EXCEPT for the following:
N1Loop1 / N1
N1Loop1 / N3
N1Loop1 / N4
IT1Loop1 / IT1
IT1Loop1 / PIDLoop1 / PID_2
When you're done, your schema should look like this:
You'll have to add a few default values to the schema, since we won't be mapping them:
Now we'll create the map. Add a new map to your project, with PurchaseOrder.xsd on the right-hand side and X12_00401_810.xsd on the left. Let's do the straight mappings first:
||ST02 and BIG02
And now we'll add some functoids...
You'll need to map the Date field to BIG01, but an X12 date is in the format CCYYMMDD. You can either modify the input xml to use this format, or use some combination of String Extract and String Concatenate functoids to alter your incoming date.
We'll need to create a new IT1Loop1 for every Item instance, so add a looping functoid and use it to connect Item with IT1Loop1.
We can get the total number of orders by using a Record Count functoid to join Item and CTT01.
And finally we can get the total number of items ordered by using a Cumulative Sum functoid to join Quantity and CTT02.
Save your map and test it using one of the xml test files you created previously.
Switch over to the orchestration and add a new message based on the 810 schema. Drag a Construct Message shape and configure it to map the xml purchase order to the X12 810. Finally, modify the Send shape and the send port in the Role Link to use the 810 message. Your orchestration should now look like this:
Deploy the solution and restart the host instance. At this point you should be able to drop your test files to the input directory and have them sent to the correct outbound directory, based on the destination party name. Remember, all we did in the solution was add a map, we haven't changed the way the messages are routed. If you open up one of the outbound files, you should see an xml representation of the 810 file. It's still in xml because we're using PassThruTransmit as the Send pipeline on both send ports. Add a reference to the BizTalk EDI Application by right-clicking the application name, selecting Properties, then the References page. Now, edit both Send ports to use the EdiSend pipeline, and change the file extension from .xml to .txt (or .edi if your prefer).
Now we'll need to create a party that represents us (our company...) and creating trading partner agreements between us, Contoso and Fabrikam. Create a new party and name it something that will represent our company ("My Company" would work). Click OK to create it, then right-click it and select New Agreement. On the General tab, configure the following:
Name: Contoso Purchase Order
Second Party / Party: Contoso
When you add the second party, you should see two new tabs at the top appear - "My Company->Contoso" and "Contoso->My Company". We're going to configure sending files to Contoso, so click "My Party->Contoso". You can configure all sorts of data for the interchange and transcation set here, but we're just going to do the minimal needed to generate an X12 file.
On the Identifiers page, set both the Sender and Receiver Id Qualifer (ISA5 and ISA7) to ZZ, and enter the party names for the ISA6 and ISA8 (i.e. My Company and Contoso). Under Additional Agreement Resolvers, set DestinationPartyName to Contoso.
On the Character set and separators page, set the Suffix to CR LF. This is optional, but it will make the file more readable.
On the Send Ports page, choose the Contoso send port.
On the Envelopes page under Transaction Set Settings, select or enter the following data:
Transaction Type: 810-Invoice
Target namespace: http://schemas.microsoft.com/BizTalk/EDI/X12/2006
Click OK to save and close your trading partner agreement. Notice that you didn't touch anything on the Contoso->My Company tab, since in this scenario we're not receiving any files from Contoso.
Repeat these steps to configre the Fabrikam trading partner agreement.
Restart the host instance (you pretty much always have to restart it when modifying party settings) and drop the two xml test files (ContosoPurchaseOrder.xml and FabrikamPurchaseOrder.xml) to the input directory. If everything has been configured properly, you should get an EDI file in each output directory. The ISA and GS of each should be different, based on which trading partner the file is going to. An example is shown below.
Technorati Tags: BizTalk