Promoting BizTalk schema properties into the message context

Posted on Wednesday, December 08, 2004 5:46 AM
Typically you choose a schema element/attribute in a schema, right click it and promote it within the BizTalk schema editor. This is very useful because when this schema is deployed it can be used in the send port "filter". So, for example, if I want to create a send port that sends Invoices to a certain location but only when the AccountCodeReference is "ABC" then I would promote the "AccountCodeReference" element in the invoice schema and then create a filter for BTS.MessageType == http://finance/invoice#invoiceroot AND InvoiceProject.AccountCodeReference == "ABC". The beauty of the promoted property is that it is in the send port filter dialogue box for you to select and use in the filter.
 
However, imagine that you have a schema that you don't own and can't change. It does not contain an element to contain the AccountCodeReference so how on earth do you promote it so you can build the send port subscription? In my case it was a flat file schema where I could not add nodes that were not part of the flat file.
 
The solution is as follows:
 
  1. Create your invoice schema - true to the business definition, without warping it to meet the needs of the physical implementation. By that I mean, don't add the AccountCodeReference just because you need it in BizTalk to help you and your Content Based Routing.
  2. "Add a new item" to your BizTalk project and choose a "Property Schema".
  3. Modify "Property1" (that was automatically created) in the property schema and rename it to "AccountCodeReference".
  4. Click on the newly created node (step 3) and go to the properties window.
  5. Set the property "Property Schema Base" to "MessageContextPropertyBase". This is the key bit. [see screen shot below] This tells the system that this promoted property does not actually exist in the document itself but the context of the document. This is the bit that allows a promoted property to exist although it does not exist as an element in the document.
  6. Right click on the root node of your invoice and choose "Promote->Show Promotions".
  7. Select the "Property Fields" tab.
  8. Click the folder icon to add a new property schema, and navigate to the property schema created in step 2.
  9. Create an orchestration with a message variable of the type created in step 1.
  10. Create a message assignment shape inside a construct message shape and you will see that you can access the promoted property as such: MyInvoiceMessageInstance(MyBizTalkProjectName.AccountCodeReference) = "ABC";
  11. Deploy and use MyBizTalkProjectName.AccountCodeReference in your send port subscription filters.
 
Ultimately you can create a message, assign a value to a promoted property and then perform Content Based Routing even though the element you promoted does not exist within the document.
 
 
Note the property Property Schema Base is set to MessageContextPropertyBase