Thursday, 2 June 2016

Check If element exists in BizTalk Orchestration - Handy solution


Most often we need to check some variable and take a call in BizTalk Orchestration to perform some task. If those variables doesn't have any business value/meaning we prefer not use Decide Shape.

I have similar scenario where I need to check whether inbound message has an element in message and populate context property accordingly.    

 I have take a approach check xPath exists in Expression Shape of the orchestration and initialize context property.

Code in Expression shape:

vHaveAttachment = System.Convert.ToString(xpath(msgInternalClaim,"string(//*[local-name()='ClaimLodgementProcess' and namespace-uri()='http://www.acord.org/schema/data/draft/ReusableDataComponents/1']/*[local-name()='ClaimLodgement' and namespace-uri()='http://www.acord.org/schema/data/draft/ReusableDataComponents/1']/*[local-name()='FileAttachment' and namespace-uri()='http://www.acord.org/schema/data/draft/ReusableDataComponents/1'])"));
if(System.String.IsNullOrEmpty(vHaveAttachment))
{
    vHaveAttachment = "Yes";
}
else
{
    vHaveAttachment = "No";
}

Code in Message Assignment shape:
msgInternalOut(TAL.myApp.Integration.Claims.Schema.Common.Attachment) = vHaveAttachment;

Note Property schema of Common.Attachment need to be set "Property Schema Base" as MessageContextPropertyBase.

Doing this once msgInternalOut published together with Attachment context property.

Hope, it help to give a understanding how to use if condition in Orchestration with xPath.
Happy to answer if you have need any clarifications.

Happy coding..


No comments:

Post a Comment