This is geared for single batches of transactions, be on the lookout for an upcoming tutorial on how to use the Batches functionality in BizTalk 2009.
This is actually a step by step tutorial on how to enable batching for outbound EDI transactions, where the input file needs to be split up from one single message but creating multiple transactions.
In my case I am going to take an invoice process. I am picking up a file from an FTP site with multiple rows, each row represents an invoice. Once all of the transactions are created, I need to release the batch.
The first think I need to do is create an orchestration that promotes the following context properties:
Because I am going to be looping through a single message, I am unable to promote values in a loop, so I need to escape the loop to promote the values.
Create an orchestration that will be called from within the loop to send it to the Microsoft’s batching orchestration. In this case I am going to create a new project called InvoiceBatcher, and the in the project create an orchestration. Add the following references:
C:\Program Files\Microsoft BizTalk Server 2006\Microsoft.BizTalk.Edi.BaseArtifacts.dll
C:\Program Files\Microsoft BizTalk Server 2006\Microsoft.BizTalk.Edi.BatchingOrchestration.dll
Reference the EDI 810 project.
Setup objects and configuration for the orchestration
1. CorrelationType which contains the context properties
2. Multi-part Message Type called EDIType representing the 810, also change the Type Modifier to Public (because we are going to be sending data to this orchestration outside of this project
3. EDIPortType which is a one way port type that points to the multi-part message type created in step 2.
4. Create a Correlation Set that is based on the CorrelationType created in step 1.
5. Create a message called OutEDIMsg that is based on the EDIType created in step 2.
6. Create a Port called Port and referencing the EDIPortType that was created in Step 3 and set it to Direct and direction set to Send.
7. Create an Int32 Orchestration Parameter called PartyNo with a direction of In
8. Create a Message Parameter called EDIMsg based on the EDIType created in step 2 with a direction of in.
9. Click on the Orchestration surface and change the Type Modifier to Public so it can be accessed by other orchestrations that will be referencing this assembly
Your orchestration view should look like this:
The orchestration surface should look like this:
The code in the Promote Context is this:
On the Send EDI Message, send the OutEDIMsg and make sure that the Initializing Correlation Set is ‘CorrelationSet’
Deploy it to the BizTalk EDI Application
Next is to create the batch release process. The first thing we need to do is create a schema that represents the table in the management database.
Create a new project called PAM and create a schema called PAMRequest.xsd. Open the newly created schema in the XML editor, not the BizTalk Schema editor and paste the following code:
<xs:schema xmlns:tns="http://PAM_Trigger" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://PAM_Trigger" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element xmlns:updategram="urn:schemas-microsoft-com:xml-updategram" updategram:Prefix="updg" minOccurs="1" maxOccurs="unbounded" name="sync">
<xs:element updategram:Prefix="updg" minOccurs="0" maxOccurs="unbounded" name="after">
<xs:element minOccurs="0" maxOccurs="unbounded" name="PAM_Control">
<xs:attribute name="DestinationParty" type="xs:string" />
<xs:attribute name="EdiMessageType" type="xs:short" />
<xs:attribute name="ActionType" type="xs:string" />
<xs:attribute name="ActionDateTime" type="xs:string" />
<xs:attribute name="UsedOnce" type="xs:boolean" />
<xs:element name="Success" />
Deploy the project to the BizTalk EDI Application
Now to create an orchestration that will actually release the batch of transactions.
Create a new project called BatchRelease
Add a reference to the PAM assembly.
Create a new orchestration called ReleaseEDIBatch
Set the Type Modifier to Public so any other orchestration can reference it.
Create the following orchestration objects (from bottom to top)
PamResponseType (Multi-part Message Type)
PamRequestType (Multi-part Message Type)
PAMPortType (Request/Response Port Type)
PAMPort (Specify Later, Send-Recieve direction)
PartnerNo (Direction:In, Int32)
The Orchestration View should look like this:
The orchestration surface looks like this:
The logic to create the PAM message in the message assignment shape is:
TempXML.LoadXml("<ns0:Request xmlns:ns0=\"http://PAM_Trigger\"><ns0:sync><ns0:after><ns0:PAM_Control DestinationParty=\""+System.Convert.ToString(PartnerNo)+"\" EdiMessageType=\"0\" ActionType=\"EdiBatchOverride\" ActionDateTime=\""+System.Convert.ToString(System.DateTime.Now)+"\" UsedOnce=\"0\" /></ns0:after></ns0:sync></ns0:Request>");
Deploy it to the BizTalk EDI Application
Now to create the actual Invoice orchestration, first reference the InvoiceBatcher and the BatchRelease assemblies. Create the multi-part message that represents the input message, and the port type to bring in the file from the ftp server. I created the following variables all as Int32:
ThisInvoiceNo (default value set at 0)
EDIMsg (InvoiceBatcher.Multi-part Message Types.EDIType)
The following Orchestration View represents the setup.
The steps for this orchestration is to receive the file, count the number of invoices, set the party number, start looping while the current invoice number is less than the invoice count. In the loop, it increases the current invoice number, injects that number into the message. The map takes that newly created message and extracts the data from the input message and creates the 810 transaction. It then sends the transaction to be batched and continues creating new transactions. Once the loop completes, it releases the batch.
The orchestration looks like this:
The Set Party Number expression shape has the following code:
The Inject Number message assignment has the following code:
The map looks like this:
The arguments to the Send EDI start orchestration shape (InvoiceBatcher.BatchPromote) are the following:
The arguments to the Release Batch start orchestration shape (BatchRelease.ReleaseEDIBatch) are the following:
The last thing of mention is to set up the send port for the ReleaseEDIBatch orchestration to bind to.
In the BizTalk EDI Application, create a request response send port set it to SQL and point to the BizTalk Management database. Sent the send and receive pipelines to DefaultXML
Set the following connection information as follows:
Bind to it and you are ready to go!