Search code examples
c#xpathbiztalkbiztalk-rule-engine

Need a way to pass a node of any type to a custom function from within the BizTalk rule engine


I'm working on a BizTalk application.

I have setup my vocabularies and have started writing the rules in the rule composer.

After evaluating a rule, I have made a function called AddValidationError which writes the validation error into the XML document being validated. The AddValidationError method is called from the Action section of the rule.

I want to pass the node that is being evaluated to the AddValidationError method to that I can determine the XPath to that node and include it as part of the error message.

I thought I can have a parameter of type TTypedXmlDocument but this doesn't allow me to pass nodes which are defined as anything other than TTypedXmlDocument, such as string, int, datetime, etc. I have noticed that the rule engine has a method called Exists which will accept any type of node and resolves it to XPath, which is what I want.

I don't want to have to copy the XPath text into the AddValidationError method as this seems messy and also any BA should be able to create new rules by simply dragging and dropping nodes and methods onscreen, i.e, they shouldn't have to know that you need to copy the XPath to the node into the AddValidationError method for it to work.

I hope this makes sense.

So coming back to the Exists predicate method, i can pass it any node and it appears to work out the XPath automatically, how can i get this functionality? or better yet, how can I pass a node of type other than TTypedXmlDocument to a method and then determine the XPath to the node passed in?

I have thought about having two definitions for each node, one that represents the value, string, int, datetime, etc and another for the same node but of the TTypedXmlDocument. Although this does work it also smells a bit so would like something better.


Solution

  • What you asking for specifically is not possible. The Compose does not see the actual xPath as an artifact, only what it resolves to.

    While you might see the xPath in the Exists Predicate, that's actually not what's being evaluated. The result of the xPath, like any other parameter, is being checked for null.

    If I had to do something like this, I would probably create an Vocabulary item with the 'path' (but not necessarily a valid xPath) to the node/field being tested in the rule.