Issue
While working on a POC about Debatching in Logic Apps using For Each, I was encountered with an below error when testing it
"InvalidTemplate. Unable to process template language expressions for action
'For_each' at line '1' and column '1658': 'The template language function
'xpath' expects its first parameter to be an XML object.
The provided value is of type 'String'.
Please see https://aka.ms/logicexpressions#xpath for usage details.'."
'For_each' at line '1' and column '1658': 'The template language function
'xpath' expects its first parameter to be an XML object.
The provided value is of type 'String'.
Please see https://aka.ms/logicexpressions#xpath for usage details.'."
Why it happened
As I had to debatch an xml message, following xpath expression was provided to ForEach action
xpath(triggerBody(),'//*[local-name()="PurchaseOrder" and namespace-uri()="http://www.adventure-works.com"]')
And when xml message was posted, the logic app was not able to apply xpath on the
triggerbody
It happened because triggerBody() is an Azure Workflow built-in FUNCTION, which is used to access
xpath(triggerBody(),'//*[local-name()="PurchaseOrder" and namespace-uri()="http://www.adventure-works.com"]')
And when xml message was posted, the logic app was not able to apply xpath on the
triggerbody
It happened because triggerBody() is an Azure Workflow built-in FUNCTION, which is used to access
the output of trigger(shorthand for trigger().outputs.body) and it’s return type
is String.
What to do
Logic app is very well equipped to process XML message apart from JSON, however if any expressions(functions) are to be applied on it then it has to be explicitly handled by casting it to xml and then use xml based functions.
So the correct expression is
In the above expression first triggerBody() (which is string) is casted in XML using xml() function and then xpath function is applied.
That's it, all worked fine.
So the correct expression is
xpath(xml(triggerBody()),'//*[local-name()="PurchaseOrder" and namespace-uri()
="http://www.adventure-works.com"]')
In the above expression first triggerBody() (which is string) is casted in XML using xml() function and then xpath function is applied.
If you have questions or suggestions, feel free to do in comments section below !!!
Do share if you find this helpful ....... Knowledge Sharing is Caring !!!!!!
Knowledge Sharing is Caring !!!!!!
Learn More about some more Logic App errors
- The request has both SAS authentication scheme and 'Bearer' authorization scheme. Only one scheme should be used
- Selected file must be between 1 and 2097152 bytes
- SplitOn property doesn't validate expression at design time
- The workflow with 'Response' action type should not have triggers with 'splitOn' property
- The template language expression 'xxx' cannot be evaluated because property 'xxx' doesn't exist. Property selection is not supported on content of type 'application/xml'
Tags:
Azure Logic App Error