Many times we feel the need of using Orchestration Variables in Maps. But there is no straight forward way to achieve it.
Below are the two ways through which we can achieve the same.
- Is to create a dummy schema with Elements which needs to be used in Maps. In below example I have created a dummy schema with Element as “Age” because I wanted to access intAge variable in Map.
- Is to assign some dummy value in map and later assign the actual value in Message Assignment shape. In below sample I have assigned “Null” (from String Concatenate functoid) and later within the Message Assignment shape assigned the value from Orchestration Variable (intAge).
Which method should be chosen depends on below points.
- 1st technique should be used when you need this variable extensively like to perform some DBLookup etc. In below example “intAge” value is used as a lookup value and required in making decisions.
- 2nd technique is preferable when you want to populate few fields without much processing.
Now let’s come to our Example.
In this post I will use this sample BizTalk solution and try to portray both the techniques.
Here we receive a simple XML having information of a person like- “Name”, “DateOfBirth” and “City”. In Orchestration will calculate the Age of the person and in Map on the basis of it’s value we will decide whether person in eligible for Voting, Marriage and Drinking or not.
As I needed value of Age variable to make decisions in Map, so I created another schema with just one element “Age” as shown below-
Created msgAge by below code-
Now next step is to create a map which takes two schemas as input- Input schema and Age Schema and generates one Output Schema.
- Drag and drop the Transform shape
- Double click -> New Map-> Select two in Source Message(msgAge & msg In in our case)
- Select output schema as destination.
- Check the box to launch BizTalk Mapper.
This will generate a map with two parts (InputMessagePart_0 & InputMessagePart_1), under “Root” record. It actually generates a multipart message with parts referring to each input/output message.
Now in map you can play around with the value of Age element. In our sample application I am performing below checks on its value.
- Age >=18 -> Eligible for Voting
- Age >=22-> Eligible for Marriage
- Age >= 25-> Eligible for Drinking Alcohol
Don’t miss to see the irony here- In India being few months younger to 25 years allows you to marry a girl or choose your Prime Minister of country (& other representatives) but makes you criminal if you drink alcohol.
Read more about how to develop and test maps with multiple source and destination schemas here.
Now let’s demonstrate the second technique to assign values in Orchestration.
For this you need Message Assignment shape along with Transform shape in Construct shape as shown below.
In Map assign Null(or any other dummy value) to all those elements for which Orchestration variables are required. For example in our sample Age element is assigned as NULL using string concatenate functoid.
Later in orchestration using Message Assignment shape assign the required values as shown above.
Hope it was helpful.