Jan 302009

I had a requirement to extract several thousand rows of X12 data from a back end database and package them up once a month into X12 EDI with a max of 5000 rows per Transaction Set and maximum 4 Transaction Sets per file.  I found that there was no out of the box way to loop around each of the 5000 rows and have them batched.  Additionally, if I had 3 of the 4 final transaction sets in the last batch, it wouldn’t release.  Since the process only runs 1 time per month, I needed the batch to package up the final 3 transactions sets and drop them off as soon as the orchestration finishes.

Here’s what I did:

ST01 and ST02 needed to be populated, in my case I set ST01 to 837 and ST02 to 0001.


You’ll  notice that the Microsoft.BizTalk.Edi.BatchingOrchestration.BatchingService subscribes to the following promoted properties.


Since my send shape was within a loop, I couldn’t simple create a correlation set and promote the properties that way.  Instead I created a separate orchestration whose only function was to promote the EDI properties the Microsoft.BizTalk.Edi.BatchingOrchestration.BatchingService orchestration was looking for.  The orchestration contained an input message parameter of the X12 EDI document I was sending out, with a correlation set initialized on the send shape.  Here is the orchestration I named orch_PromoteEDIBatchingProperties.odx


My ct_EDIPropertiesToBePromoted properties:


My main orchestration simply called this orchestration and the messages were successfully being picked up by the Microsoft.BizTalk.Edi.BatchingOrchestration.BatchingService orchestration.  Now I needed some way to release the final batch upon orchestration completion.

If you look at the properties of the BatchControlMessageRecvLoc Receive Location, you’ll notice that it executes a simple stored procedure that returns a message to release the batch.  It executes the Stored Procedure edi_GetControlMessage that looks at the PAM_Control Table found in the BizTalkMgmtDb.


All I needed to do was to populate the PAM_Control table with a row that the stored procedure would pick up saying it needed to terminate the batch.  I simply inserted the DestinationPartyID, EdiMessageType, ActionType, ActionDateTime, and UsedOnce values needed into the table and it releases the batch as soon as the sproc is executed, in this case every 30 seconds.  I created a schema for a table insert and in my case inserted 15, 0, EdiBatchOverride, System.DateTime.Now, and 0 for the PAM_Control Table values.  As soon as the Stored Procedure ran it flags the row as having been UsedOnce.


The important parts of my orchestration are shown below


The MessageAssignment shape has the following code.

//Instantiate your XmlDocument
xml_Temp = new System.Xml.XmlDocument();
//Load the XmlDocument with the information needed for the PAM_Control Table
xml_Temp.LoadXml(“<ns0:Request xmlns:ns0=\”PAM_Control\”><ns0:sync><ns0:after><ns0:PAM_Control DestinationParty=\”15\” EdiMessageType=\”0\” ActionType=\”EdiBatchOverride\” ActionDateTime=\””+System.DateTime.Now.ToString()+”\” UsedOnce=\”0\” /></ns0:after></ns0:sync></ns0:Request>”);
//Assign your XmlDocument to your msg_BatchControlRequest
msg_BatchControlRequest = xml_Temp;

I am planning on creating two parameterized orchestrations that will be able to be used as called orchestrations for my other projects instead of this approach that is coded within my main orchestration.

  • Hey, that was interesting,

    Wise decision, I think I will use your approach nect time

    Thanks for bringing this up

  • güzel davetiye örnekleri, davetiye modelleri, düğün davetiyeleri

  • BizTalk is a business process management (BPM) server that enables companies to automate and optimize business processes. This includes powerful, familiar tools to design, develop, deploy, and manage those processes.

  • Buildings are not very cheap and not everyone is able to buy it. But, mortgage loans was invented to help people in such situations.

  • RiteshC

    This is the only post I found how to batch EDI transactions based on “Custome release” feature of the batch which we need to do most of the time when we get a batch of proprietary flat file containing multiple trans and we need to make those to X12 trans.
    This post is really usefull.

  • The last code is totally out of my mind.

  • I find this site as very informative source. I am impressed by the ways in which the author delivers the message to his readers. I am very curious person, but here I was able to find answers to my query. I would love to track your future posts. Regards, James

  • This way of using blogs is very good.

  • I liked your biztalk. this is all very impressive.

  • Any thought on how to assign %SourceFileName% and use the batching service? I need to define the %SourceFileName% so when the batching service sends the file, that value needs to be promoted.