{tocify} $title={Table of Contents}
Problem
While doing a POC - Getting Started with Logic Apps - What happened to the Request?
I tried to use the orderID node's value in the subject of the
send email action from the triggerBody(),the message to trigger logic app is as below
<purchaseOrder>
<orderID>PO0029</orderID>
<orderDate>2019-10-20</orderDate>
<description>Discount applied on the Order</description>
<shipTo>
<name>Mike Taylor</name>
<street>MG Road</street>
<city>Pune</city>
<state>MH</state>
<pin>411001</pin>
<country>India</country>
</shipTo>
<billTo>
<name>Mike Taylor</name>
<street>MG Road</street>
<city>Pune</city>
<state>MH</state>
<pin>411001</pin>
<country>India</country>
<emailID>maheshkumar.tiwari@emtecinc.com</emailID>
</billTo>
</purchaseOrder>
However I was encountered with an error
InvalidTemplate.
Unable to process template language expressions in action 'Send_email' inputs
at line '1' and column '1607': 'The template language expression
'triggerBody().purchaseOrder.orderID' cannot be evaluated because property
'purchaseOrder' doesn't exist. Property selection is not supported on content
of type 'application/xml'. Please see https://aka.ms/logicexpressions for usage
details.'.
Why it happened
It is clear from error that the Logic App runtime was not
able to find purchaseOrder property although the node purchaseOrder is present
and another thing it’s pointing out is that property selection is not supported
on content of type ‘application/xml’.
And what I was doing is sending xml as message body, content
type as ‘application/xml’ and with 'triggerBody().purchaseOrder.orderID'
expression I was asking logic app runtime to fetch the value of orderID under purchaseOrder
of triggerBody() with assumption that triggerBody() always returns JSON upon
which property selection can be done – And this assumption was wrong.
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. But when you trigger
a logic app with content type as ‘application/JSON’ , the logic app runtime implicitly
applies the JSON parsing on it and thus the triggerBody() returns JSON document
as output.
To get the entire body you just use triggerBody() and with
the property suffix added to it , value of that field is returned.
So if I had to pass following JSON message
{
"orderID": "PO0029",
"orderDate": "2019-10-20",
"description": "Discount applied
on the Order",
"shipTo": {
"name": "Mike
Taylor",
"street": "MG Road",
"city": "Pune",
"state": "MH",
"pin": "411001",
"country": "India"
},
"billTo": {
"name": "Mike Taylor",
"street": "MG Road",
"city": "Pune",
"state": "MH",
"pin": "411001",
"country": "India",
"emailID": "maheshkumar.tiwari@emtecinc.com"
}
}
then triggerBody()
would give me above whole json whereas 'triggerBody().billTo.emailID'
would give me value as maheshkumar.tiwari@emtecinc.com
In my case , here the content passed on was XML and
therefore no JSON parsing was applied and thus leading to error.
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 either by casting it to JSON using xml based
functions.
Here, I need to get value of orderID node thus the message has to be casted
to JSON and then access the property (property is JSON = node in XML) by
following expression
json(xml(triggerBody())).purchaseOrder.orderID
In the above expression first triggerBody() (which is
string) is casted in XML using xml() function and then casted it in JSON using json() function. And it worked
absolutely fine.
However with understanding that json function is used to convert
xml then it can do it directly , thus directly passed on triggerBody to it and
it works too.
json(triggerBody()).purchaseOrder.orderID
Note : First
triggerBody is converted to JSON by using json(triggerBody()) and then using dot operator
particular property is accessed
Out of curiosity, the another syntax which can be used
json(triggerBody())['purchaseOrder']['orderID']
If there is any another way then do share !!!
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 !!!!!!
Learn More about Logic App
- Developing Logic app standard workflow which uses Map locally and deploying to Azure
- Developing Logic App Standard Workflow Using Visual Studio Code | Create Logic App Standard Workflow Using Visual Studio Code
- Logic App - Xml to Json using Liquid Map | Append in Liquid Map
- How to use Azure Event Grid Custom Topic | Publishing and Subscribing from Azure Event Grid Custom Topic using Logic App
- Using Azure Storage Account Table as Config Store for Logic Apps | How to read and write from Logic App to Azure Storage Account Table
- Get Logic App Name in Logic App
- Difference between Logic App Consumption and Logic App Standard
- Getting Started with Logic App Standard | Overview of Logic App Standard | Basics of Logic App Standard
- How to find count of Logic App executions using Azure Portal
- Azure Functions vs Azure Logic App | Difference between Azure Functions and Azure Logic App
- Getting started with Logic App : Liquid Map | Using Liquid template in Logic app
- How to get actual error message of Scope in Logic App | Exception Handling in Logic app
- Interview questions and answers on Logic Apps | Interview questions for azure logic app developers
- How to execute Stored Procedure in Logic App | How to connect to SQL in Logic App
- How to get current date in logic app | How to format date time in Logic App
- BizTalk Developer getting started with Logic App
- Getting Started with Logic Apps - Fundamentals
- Getting Started with Logic Apps - Enterprise Application Integration
- Getting Started with Logic Apps - AS2
- Getting Started with Logic Apps - EDI X12 Fundamentals
- Getting Started with Logic Apps - XML to EDI X12
- Getting Started with Logic Apps - EDI X12 to XML
- Getting Started with Logic Apps - What happened to the Request?
- Inserting Multiple Records In On Prem SQL Using Logic App
- Inserting data in On Premises SQL Database using Logic Apps
- Installing and Configuring On Premises Data Gateway - By adding user to Active Directory
- XML Batching(Aggregation) in Logic App
- Batching(Aggregating) messages in Logic App
- Debatching(Splitting) JSON Message in Logic Apps - ForEach and SplitOn
- Debatching(Splitting) XML Message in Logic Apps - ForEach and SplitOn
- Securing Logic App with Azure Active Directory authentication
- Removing ns0: prefix from xml output from BizTalk/Logic app XSLT map
- Using Managed Identity in Logic Apps for Calling Active Directory Secured Function App
- Logic Apps : Fetching ISA and GS Segment Values From Interchange Envelope and Mapping
- Logic Apps : For Each Inside a For Each - Fetching values from field in an array inside an array
- Developing Logic app standard workflow which uses Map locally and deploying to Azure
- Developing Logic App Standard Workflow Using Visual Studio Code | Create Logic App Standard Workflow Using Visual Studio Code
- Logic App - Xml to Json using Liquid Map | Append in Liquid Map
- How to use Azure Event Grid Custom Topic | Publishing and Subscribing from Azure Event Grid Custom Topic using Logic App
- Using Azure Storage Account Table as Config Store for Logic Apps | How to read and write from Logic App to Azure Storage Account Table
- Get Logic App Name in Logic App
- Difference between Logic App Consumption and Logic App Standard
- Getting Started with Logic App Standard | Overview of Logic App Standard | Basics of Logic App Standard
- How to find count of Logic App executions using Azure Portal
- Azure Functions vs Azure Logic App | Difference between Azure Functions and Azure Logic App
- Getting started with Logic App : Liquid Map | Using Liquid template in Logic app
- How to get actual error message of Scope in Logic App | Exception Handling in Logic app
- Interview questions and answers on Logic Apps | Interview questions for azure logic app developers
- How to execute Stored Procedure in Logic App | How to connect to SQL in Logic App
- How to get current date in logic app | How to format date time in Logic App
- BizTalk Developer getting started with Logic App
- Getting Started with Logic Apps - Fundamentals
- Getting Started with Logic Apps - Enterprise Application Integration
- Getting Started with Logic Apps - AS2
- Getting Started with Logic Apps - EDI X12 Fundamentals
- Getting Started with Logic Apps - XML to EDI X12
- Getting Started with Logic Apps - EDI X12 to XML
- Getting Started with Logic Apps - What happened to the Request?
- Inserting Multiple Records In On Prem SQL Using Logic App
- Inserting data in On Premises SQL Database using Logic Apps
- Installing and Configuring On Premises Data Gateway - By adding user to Active Directory
- XML Batching(Aggregation) in Logic App
- Batching(Aggregating) messages in Logic App
- Debatching(Splitting) JSON Message in Logic Apps - ForEach and SplitOn
- Debatching(Splitting) XML Message in Logic Apps - ForEach and SplitOn
- Securing Logic App with Azure Active Directory authentication
- Removing ns0: prefix from xml output from BizTalk/Logic app XSLT map
- Using Managed Identity in Logic Apps for Calling Active Directory Secured Function App
- Logic Apps : Fetching ISA and GS Segment Values From Interchange Envelope and Mapping
- Logic Apps : For Each Inside a For Each - Fetching values from field in an array inside an array
Is there any way we can capture Invalid Template and return in response- actual error as the standard error 502 in case of invalid template.
ReplyDelete