Monday, February 20, 2012

How to initialize correlation set multiple times?

There was a question in Microsoft BizTalk Server General Forum where the requirement was to promote values on the messages extracted from a batch of messages using orchestration.

How it could be implemented?

To promote the properties in orchestration one need to initialize the correlation set as demonstrated by Sarvana Kumar in his blog. But you can initialize the correlation set only once so here is the way to initialize correlation set multiple times.

I am just extending the code shared by Stephen W. Thomas for Envelope and XPath Debatching in an Orchestration Lab

Download the code from above link and follow these steps:
Step 1. Run the Visual Studio Conversion Wizard to convert the solution.
Step 2. Remove PortDebatching project from solution you don’t need it for this excercise.

 Step 3. Open the XPathSample.odx and create a correlation type and correlation set as shown below:

Step 4. Create a variable with name CompanyName and type string and initialize it as shown below:
CompanyName=xpath(SingleInput,"string(/*[local-name()='Data' and namespace-uri()='']/*[local-name()='Company' and namespace-uri()=''])");

Step 5. Drop a message assignment shape in the ConstrustMapped shape and use the following expression:

Step 6. Select the send shape SendSingleMessage and initialize the correlation set Correlation_Party

If you will try to build this BizTalk Project now you will get the compile time error: “'Correlation_Party': a correlation may be initialized only once

How to get rid of error 'Correlation_Party': a correlation may be initialized only once”?

- Add a scope shape to the loop and set the Transaction Type for this scope to Automic/Long Running/None.

Note: The only requirement is to have scope shape with the correlation set defined on this scope level. You can set the transaction type to None or atomic or long running  for the scope depending on your requirement.

- Cut the correlation set Correlation_Party  from orchestration level and paste it to the level of this new scope.

- Move the send shape to this new scope.

Note: Check once again that the send port is initializing the correlation set 'Correletaion_Party'.

Build and deploy the solution and you will see Destination Party get promoted with the value of company name for each message generated in the loop.

Rohit Sharma