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:
SingleMapped(BTS.DestinationParty)=CompanyName;

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.


Cheers,
Rohit Sharma

8 comments:

saty said...

I was wondering why do we need an Atomic scope at first place? AFAIK, a non-transactional scope would be sufficient. Please clarify.

Rohit Sharma said...

Thanks for pointing this out. There is no requirement is of using only atomic scope the only requirement is to have scope shape the blog has been updated with this information.

Ranadheer said...

I have a Orchestration which is atomic ( must and should can remove it) now i have a loop in it and i need to promote the property , i added a scope of None type and did the above thing but it is not getting promoted .. need some help arround this....

Rohit Sharma said...

Make sure that the send port inside the scope with transaction type 'none' is initializing the correlation set.

Abhishek said...

Hi Rohit,
Is it possible to initialize the correlation on send shape as i am getting correlation exception while implementing my Orchestration.

regards
Abhishek

Rohit Sharma said...

Abhishek please go through again in above demonstration I have initialized the correlation on send shape.

Martin said...

Rohit, just wanted to let you know how thankful I am for this post! This could have been a real timesink for me (and my client), but thanks to you I breezed through this problem.

Know that posts like this from guys like you are a real godsend for sometimes struggling biztalk developers!

Again, thanks,

Martin

Rohit Sharma said...

Martin I am glad to know your experience.

Post a Comment