cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ianwuk
Post Patron
Post Patron

How to read fact/values from JSON?

Hello Everyone.

 

I have managed to extract the attachment of a Teams message in JSON, which partly looks like this:

ianwuk_0-1673330665087.png

For the above key and value, how can I make it so I can interact with them?  E.g. create a condition 'if "Monitor status" contains DOWN then do something?

 

Many thanks for any help.

2 ACCEPTED SOLUTIONS

Accepted Solutions

Hopefully this gets what you're looking for. Note that I've just got a manual trigger and storing the JSON directly in the Compose for this example.

 

See full flow below. I'll go into each of the actions.

grantjenkins_0-1673338320776.png

 

Compose contains the JSON data you sent through. You would already have this as part of the trigger attachment content.

grantjenkins_1-1673338411674.png

 

XML is a Compose that converts the JSON data to XML so we can apply XPath expressions. Note that I've also added a root element to ensure it's valid XML. The expression used is:

xml(json(concat('{"root": ', outputs('Compose'), '}')))

//Your expression would likely look like the following:
xml(json(concat('{"root": ', triggerBody()?['attachments'][0]['content'], '}')))

grantjenkins_2-1673338478600.png

 

Condition checks to see if any items within any of the facts arrays have a name containing 'Monitor status' and a value containing 'DOWN'. If at least one item is returned, then the Condition will return true and would run your Reply in channel with a message in the Yes branch. The expression for the condition is:

length(xpath(outputs('XML'), '//sections/facts[contains(name, "Monitor status") and contains(value, "DOWN")]'))

grantjenkins_4-1673338673658.png


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.

View solution in original post

@ianwuk That's some crazy (horrible) JSON you've got there 🙂

 

See full flow below. I'll go into each of the actions.

grantjenkins_0-1673412210464.png

 

Compose contains your JSON data.

grantjenkins_1-1673412265897.png

 

XML is a Compose that converts your Table data to XML. The expression also removes the style rows as they cause issues in the XML due to not having closing tags. The expression is below:

xml(concat('<table>', slice(outputs('Compose')?['text'], indexOf(outputs('Compose')?['text'], '<tbody>'))))

grantjenkins_2-1673412399441.png

 

Select Codes retrieves an array of the Stock Codes. It uses the following expressions:

//From
split(last(xpath(outputs('XML'), '//tbody/tr/td/text()')), ' ')

//Map
trim(item())

grantjenkins_3-1673412513461.png

 

Select Numbers retrieves all the numbers (will end up with an array of arrays in this instance). It uses the following expressions:

//From
xpath(outputs('XML'), '//tbody/tr/td/pre/code/text()')

//Map
split(trim(item()), decodeUriComponent('%0A'))

grantjenkins_4-1673412614444.png

 

Initialize variable total creates an integer variable called total that stores the total number of rows from the JSON. The expression used is:

length(body('Select_Codes'))

grantjenkins_5-1673412802944.png

 

Initialize variable index creates an integer variable called index initially set to 0. This will be uses when we loop over each of the rows in our Do Until loop.

grantjenkins_6-1673412883749.png

 

Initialize variable rows creates an array variable called rows. It's initially set to an empty array and will eventually contain all our objects (rows of data).

grantjenkins_7-1673412974254.png

 

Do until will continue to loop until index is equal to total. Each time through the loop index will be increased by 1. We use the value of index to retrieve the values from our arrays at that index to build up our objects. We then add the object to the rows array. Note that I've also changed the limits so Count is 1000 which will allow for the loop to run 1000 times (needs to be at least the same or more than the number of rows we have).

 

grantjenkins_8-1673413013980.png

 

Append to array variable rows will build up each object using the current index. The object will then be appended to the rows array. Below are the expressions used for each property:

//stock_code
body('Select_Codes')[variables('index')]

//total_sku_have_stock
int(trim(body('Select_Numbers')[0][variables('index')]))

//total_sku_enable
int(trim(body('Select_Numbers')[1][variables('index')]))

//enable_lower_than_stock_percentage
float(trim(body('Select_Numbers')[2][variables('index')]))

 

The full object expression is below (can just copy/paste this directly into the action).

{
    "stock_code": @{body('Select_Codes')[variables('index')]},
    "total_sku_have_stock": @{int(trim(body('Select_Numbers')[0][variables('index')]))},
    "total_sku_enable": @{int(trim(body('Select_Numbers')[1][variables('index')]))},
    "enable_lower_than_stock_percentage": @{float(trim(body('Select_Numbers')[2][variables('index')]))}
}

grantjenkins_9-1673413339143.png

 

Increment variable index increases the index variable by 1 each time through the loop so we can get the next set of data.

grantjenkins_10-1673413389720.png

 

After the loop has completed, the variable rows should contain all of our rows/data. We then have Create HTML table using the output from the rows variable. This should give us our HTML table with the correct data format.

grantjenkins_11-1673413465989.png

 

Below is what the HTML table would look like.

grantjenkins_14-1673414064926.png

 

XML Stock is a Compose that converts our rows to XML which will be used in the Condition.

xml(json(concat('{"root": { value:', variables('rows'), '}}')))

grantjenkins_12-1673413570095.png

 

Condition uses the following expression to check if any enable_lower_than_stock_percentage column >= 25. If true, then it will go into the Yes branch to run whatever you want to do.

length(xpath(outputs('XML_Stock'), '//root/value[enable_lower_than_stock_percentage >= 25]'))

grantjenkins_13-1673413785769.png


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.

 

 

 

 


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.

View solution in original post

17 REPLIES 17
CFernandes
Super User
Super User

Hey @ianwuk 

 

Have you tried using "Parse JSON" action? For details see - https://zeitgeistcode.com/power-automate-parse-json/ 

CFernandes_0-1673332936445.png

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

 

P.S. take a look at my blog here and like & subscribe to my YouTube Channel thanks.

 

ianwuk
Post Patron
Post Patron

Thank you for replying @CFernandes 

 

Yes, I did a parse json and now I have this - is it correct?

ianwuk_1-1673333678227.png

 

The fact I want is:


"name": "Monitor status ",
"value": "<p>DOWN</p>"

Many thanks!

grantjenkins
Super User
Super User

@ianwuk Are you able to show your full JSON output from your Teams message? We should be able to achieve what you want without having to use a loop (Apply to each).


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.

Hey @ianwuk - Many loops makes it confusing\tricky.. Can you please paste the JSON payload as mentioned by @grantjenkins 

ianwuk
Post Patron
Post Patron

@grantjenkins I can't show it all as it contains PII, but how would I go about, theoretically, doing this without a loop?

 

My flow works like this:

When a new channel message is added.

COMPOSE - triggerBody()?['attachments'][0]['content']

INITIALISE VARIABLE - Name: Facts, Type: String, Value: Output of COMPOSE.
PARSE JSON using schema of Output of COMPOSE.

APPLY TO EACH - SECTIONS (from the JSON).

APPLY TO EACH - FACTS

CONDITIONS: NAME = x AND VALUE = y (from FACTS)
ACTION - Reply in channel with a message


Not sure if that helps?  But thanks very much!

Would you be able to show the full JSON, but just change the values to something to remove the PII. It looks from your flow that you have an array called sections and within that an array of facts, but not sure without seeing it. Can definitely do it without a loop.


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.
ianwuk
Post Patron
Post Patron

@CFernandes  @grantjenkins 

Okay, here is the JSON is full.

{
"summary": "Site24x7 Alert",
"themeColor": "C63728",
"sections": [
{
"facts": [
{
"name": "Display Name",
"value": "<p>Zylker Monitor</p>"
},
{
"name": "Monitor Type",
"value": "<p>URL</p>"
},
{
"name": "Site monitored",
"value": "<p><a href=\"http://zylker.com\">http://zylker.com</a></p>"
},
{
"name": "Monitor status ",
"value": "<p>DOWN</p>"
},
{
"name": "Down since",
"value": "<p>10 Jan 2023 01:56:07 ICT</p>"
},
{
"name": "Downtime in UNIX Format",
"value": "<p>1673333772500</p>"
},
{
"name": "Customer Name",
"value": "<p>mspCustomer</p>"
},
{
"name": "Monitor Group Name",
"value": "<p>Zylker Web Group</p>"
},
{
"name": "Reason",
"value": "<p>Service Unavailable</p>"
},
{
"name": "Alarm Details",
"value": "<p><a href=\"https://www.site24x7.com/app/client#/alarms/412304000000025001/Summary\">https://www.site24x7.com/app/client#/alarms/412304000000025001/Summary</a></p>"
}
],
"activityTitle": "<p>Zylker Monitor is Down</p>",
"activitySubtitle": "<p>Website</p>",
"activityImage": "https://www.site24x7.com/app/static/images?name=site24x7-down-icon.png",
"markdown": true,
"startGroup": false
}
],
"potentialAction": [
{
"inputs": [
{
"isMultiSelect": false,
"choices": [
{
"display": "P",
"value": "18"
},
{
"display": "O",
"value": "17"
},
{
"display": "N",
"value": "16"
},
{
"display": "M",
"value": "15"
},
{
"display": "L",
"value": "14"
},
{
"display": "K",
"value": "13"
},
{
"display": "K",
"value": "12"
},
{
"display": "J",
"value": "11"
},
{
"display": "I",
"value": "10"
},
{
"display": "H",
"value": "9"
},
{
"display": "G",
"value": "8"
},
{
"display": "G",
"value": "7"
},
{
"display": "F",
"value": "6"
},
{
"display": "E",
"value": "5"
},
{
"display": "D",
"value": "4"
},
{
"display": "C",
"value": "3"
},
{
"display": "B",
"value": "2"
},
{
"display": "A",
"value": "1"
}
],
"@type": "MultichoiceInput",
"id": "technicianList",
"title": "Choose Technician",
"isRequired": true
}
],
"actions": [
{
"hideCardOnInvoke": false,
"target": "https://gadgets.zoho.com/office365/teamsconnector/action?zservice=Site24x7&requestFrom=US&method=pos...",
"body": "{\\\"monitor_id\\\":412304000000025001,\\\"technician_zuid\\\":\\\"{{technicianList.value}}\\\",\\\"thirdparty_service_id\\\":412304000031544017,\\\"msp_userid\\\":412304000000025001}",
"@type": "HttpPOST",
"@id": "1e448ad1-28c7-4944-9b00-07ea6098541a",
"name": "Ok",
"isPrimaryAction": false
}
],
"@type": "ActionCard",
"@id": "557340da-8834-4913-8089-40ec57365f70",
"name": "Assign Technician",
"isPrimaryAction": false
},
{
"actions": [
{
"hideCardOnInvoke": false,
"target": "https://gadgets.zoho.com/office365/teamsconnector/action?zservice=Site24x7&requestFrom=US&method=pos...",
"body": "{\\\"monitor_id\\\":412304000000025001,\\\"thirdparty_service_id\\\":412304000031544017,\\\"msp_userid\\\":412304000000025001}",
"@type": "HttpPOST",
"@id": "83c5e7ba-0d18-4eb9-a51a-c827cb633f30",
"name": "Confirm Mark as Maintenance",
"isPrimaryAction": false
}
],
"@type": "ActionCard",
"@id": "72921f76-e7fe-4cea-8ca3-73958c49680b",
"name": "Mark as Maintenance",
"isPrimaryAction": false
},
{
"targets": [
{
"os": "default",
"uri": "https://www.site24x7.com/login.html?serviceurl=%2Fapp%2Fclient&ncredirecturl=%2Fhome%2Fmonitors%2F41..."
}
],
"@type": "OpenUri",
"@id": "fb57eb17-01bb-4d3b-b307-3563ce569d81",
"name": "View Online Reports",
"isPrimaryAction": false
}
]
}

Hopefully this gets what you're looking for. Note that I've just got a manual trigger and storing the JSON directly in the Compose for this example.

 

See full flow below. I'll go into each of the actions.

grantjenkins_0-1673338320776.png

 

Compose contains the JSON data you sent through. You would already have this as part of the trigger attachment content.

grantjenkins_1-1673338411674.png

 

XML is a Compose that converts the JSON data to XML so we can apply XPath expressions. Note that I've also added a root element to ensure it's valid XML. The expression used is:

xml(json(concat('{"root": ', outputs('Compose'), '}')))

//Your expression would likely look like the following:
xml(json(concat('{"root": ', triggerBody()?['attachments'][0]['content'], '}')))

grantjenkins_2-1673338478600.png

 

Condition checks to see if any items within any of the facts arrays have a name containing 'Monitor status' and a value containing 'DOWN'. If at least one item is returned, then the Condition will return true and would run your Reply in channel with a message in the Yes branch. The expression for the condition is:

length(xpath(outputs('XML'), '//sections/facts[contains(name, "Monitor status") and contains(value, "DOWN")]'))

grantjenkins_4-1673338673658.png


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.
ianwuk
Post Patron
Post Patron

Wow!  Thank you so much for the help and the detailed explanation @grantjenkins.

Can I bother you with a follow up question please?

I have another webhook that sends data to a Teams channel, and then I want to do something with it, based on a condition.

Again, Teams just sees it as an attachment, but it is really a table.

Power Automate grabs it like this from the Teams message attachment content data:

{
  "text""<table>\r\n<col style=\"width:14.61%\"><col style=\"width:24.72%\"><col style=\"width:20.22%\"><col style=\"width:40.45%\">\r\n<tbody>\r\n<tr>\r\n<td>stock_code</td>\r\n<td>total_sku_have_stock</td>\r\n<td>total_sku_enable</td>\r\n<td>enable_lower_than_stock_percentage</td>\r\n</tr>\r\n<tr>\r\n<td>TOPS_AG_054 TOPS_AG_008 TOPS_AG_419 TOPS_AG_047 TOPS_AG_711 TOPS_AG_581 TOPS_AG_020 TOPS_AG_056 TOPS_AG_031 TOPS_AG_157 TOPS_AG_432</td>\r\n<td>\r\n<pre><code>            16582\n            17891\n            13929\n            14823\n            17228\n            17825\n            12871\n            15372\n            11754\n             7532\n            14476\n</code></pre>\r\n</td>\r\n<td>\r\n<pre><code>        13263\n        14510\n        11462\n        12250\n        14308\n        14850\n        10745\n        12892\n         9933\n         6626\n        13032\n</code></pre>\r\n</td>\r\n<td>\r\n<pre><code>                          20.02\n                          18.90\n                          17.71\n                          17.36\n                          16.95\n                          16.69\n                          16.52\n                          16.13\n                          15.49\n                          12.03\n                           9.98\n</code></pre>\r\n</td>\r\n</tr>\r\n</tbody>\r\n</table>"
}
How can I format that to look like a table, so it matches the Teams message?
ianwuk_0-1673394220039.png

 



Like this (below is how the first line should look)?

stock_code      total_sku_have_stock        total_sku_enable      enable_lower_than_stock_percentage
TOPS_AG_054         16582                               13263                           20.02

 

I then want to set a condition where if any value in the enable_lower_than_stock_percentage column >= 25.00 then do something.

Any help would really be appreciated.

Thanks so much!
 

@ianwuk That's some crazy (horrible) JSON you've got there 🙂

 

See full flow below. I'll go into each of the actions.

grantjenkins_0-1673412210464.png

 

Compose contains your JSON data.

grantjenkins_1-1673412265897.png

 

XML is a Compose that converts your Table data to XML. The expression also removes the style rows as they cause issues in the XML due to not having closing tags. The expression is below:

xml(concat('<table>', slice(outputs('Compose')?['text'], indexOf(outputs('Compose')?['text'], '<tbody>'))))

grantjenkins_2-1673412399441.png

 

Select Codes retrieves an array of the Stock Codes. It uses the following expressions:

//From
split(last(xpath(outputs('XML'), '//tbody/tr/td/text()')), ' ')

//Map
trim(item())

grantjenkins_3-1673412513461.png

 

Select Numbers retrieves all the numbers (will end up with an array of arrays in this instance). It uses the following expressions:

//From
xpath(outputs('XML'), '//tbody/tr/td/pre/code/text()')

//Map
split(trim(item()), decodeUriComponent('%0A'))

grantjenkins_4-1673412614444.png

 

Initialize variable total creates an integer variable called total that stores the total number of rows from the JSON. The expression used is:

length(body('Select_Codes'))

grantjenkins_5-1673412802944.png

 

Initialize variable index creates an integer variable called index initially set to 0. This will be uses when we loop over each of the rows in our Do Until loop.

grantjenkins_6-1673412883749.png

 

Initialize variable rows creates an array variable called rows. It's initially set to an empty array and will eventually contain all our objects (rows of data).

grantjenkins_7-1673412974254.png

 

Do until will continue to loop until index is equal to total. Each time through the loop index will be increased by 1. We use the value of index to retrieve the values from our arrays at that index to build up our objects. We then add the object to the rows array. Note that I've also changed the limits so Count is 1000 which will allow for the loop to run 1000 times (needs to be at least the same or more than the number of rows we have).

 

grantjenkins_8-1673413013980.png

 

Append to array variable rows will build up each object using the current index. The object will then be appended to the rows array. Below are the expressions used for each property:

//stock_code
body('Select_Codes')[variables('index')]

//total_sku_have_stock
int(trim(body('Select_Numbers')[0][variables('index')]))

//total_sku_enable
int(trim(body('Select_Numbers')[1][variables('index')]))

//enable_lower_than_stock_percentage
float(trim(body('Select_Numbers')[2][variables('index')]))

 

The full object expression is below (can just copy/paste this directly into the action).

{
    "stock_code": @{body('Select_Codes')[variables('index')]},
    "total_sku_have_stock": @{int(trim(body('Select_Numbers')[0][variables('index')]))},
    "total_sku_enable": @{int(trim(body('Select_Numbers')[1][variables('index')]))},
    "enable_lower_than_stock_percentage": @{float(trim(body('Select_Numbers')[2][variables('index')]))}
}

grantjenkins_9-1673413339143.png

 

Increment variable index increases the index variable by 1 each time through the loop so we can get the next set of data.

grantjenkins_10-1673413389720.png

 

After the loop has completed, the variable rows should contain all of our rows/data. We then have Create HTML table using the output from the rows variable. This should give us our HTML table with the correct data format.

grantjenkins_11-1673413465989.png

 

Below is what the HTML table would look like.

grantjenkins_14-1673414064926.png

 

XML Stock is a Compose that converts our rows to XML which will be used in the Condition.

xml(json(concat('{"root": { value:', variables('rows'), '}}')))

grantjenkins_12-1673413570095.png

 

Condition uses the following expression to check if any enable_lower_than_stock_percentage column >= 25. If true, then it will go into the Yes branch to run whatever you want to do.

length(xpath(outputs('XML_Stock'), '//root/value[enable_lower_than_stock_percentage >= 25]'))

grantjenkins_13-1673413785769.png


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.

 

 

 

 


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.
ianwuk
Post Patron
Post Patron

@grantjenkins This is amazing!  I'm sorry for the late reply.  I'll go through it and give it a try.

 

How can I learn more about Power Automate to be able to do stuff like this myself?  What would you recommend?

 

Thanks again, I really appreciate it!

ianwuk
Post Patron
Post Patron

@grantjenkins 

I am trying to make it so that the JSON step uses the attachment details from the Teams message and is not hardcoded.

I have changed the start of my flow to be this:

ianwuk_1-1673579332223.png


I assume I then need to add a parse JSON with the schema from the above output?  This is an Apply to Each for each message attachments item.

 

ianwuk_0-1673583884210.png

And after that is the start of your flow steps with XML, but it refers to Parse_JSON above?  -

xml(concat('<table>', slice(outputs('Parse_JSON')?['text'], indexOf(outputs('Parse_JSON')?['text'], '<tbody>'))))

Is that correct?  I'm a bit confused.

Thanks so much!

ianwuk
Post Patron
Post Patron

@grantjenkins I'm sorry to bother you, but I cannot seem to get this flow to work.

It fails on the Select_Codes step, with the following message:

Unable to process template language expressions in action 'Select_Codes' inputs at line '0' and column '0': 'The template language function 'split' expects its first parameter to be of type string.

Here is how my flow looks up to that point:

1 - I get the Teams message details.
2 - I use a Compose to get the attachment data - body('Get_message_details')?['attachments'][0]?['content']

3 - This gives me output like this, which looks correct:

{
"text": "<table>\r\n<col style=\"width:14.61%\"><col style=\"width:24.72%\"><col style=\"width:20.22%\"><col style=\"width:40.45%\">\r\n<tbody>\r\n<tr>\r\n<td>stock_code</td>\r\n<td>total_sku_have_stock</td>\r\n<td>total_sku_enable</td>\r\n<td>enable_lower_than_stock_percentage</td>\r\n</tr>\r\n<tr>\r\n<td>TOPS_AG_054 TOPS_AG_008 TOPS_AG_419 TOPS_AG_047 TOPS_AG_711 TOPS_AG_581 TOPS_AG_020 TOPS_AG_056 TOPS_AG_031 TOPS_AG_157 TOPS_AG_432</td>\r\n<td>\r\n<pre><code> 16768\n 18422\n 14121\n 14982\n 17595\n 18243\n 13139\n 15894\n 11880\n 7546\n 14900\n</code></pre>\r\n</td>\r\n<td>\r\n<pre><code> 13324\n 14641\n 11593\n 12317\n 14532\n 15103\n 10913\n 13312\n 9993\n 6666\n 13440\n</code></pre>\r\n</td>\r\n<td>\r\n<pre><code> 20.54\n 20.52\n 17.90\n 17.79\n 17.41\n 17.21\n 16.94\n 16.25\n 15.88\n 11.66\n 9.80\n</code></pre>\r\n</td>\r\n</tr>\r\n</tbody>\r\n</table>"
}

4 - Your XML step runs - xml(json(concat('{"root": ', outputs('Compose'), '}')))

But the input that the XML step gets from Compose is this:

 

<root><text>&lt;table&gt;
&lt;col style="width:14.61%"&gt;&lt;col style="width:24.72%"&gt;&lt;col style="width:20.22%"&gt;&lt;col style="width:40.45%"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;stock_code&lt;/td&gt;
&lt;td&gt;total_sku_have_stock&lt;/td&gt;
&lt;td&gt;total_sku_enable&lt;/td&gt;
&lt;td&gt;enable_lower_than_stock_percentage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;TOPS_AG_054 TOPS_AG_008 TOPS_AG_419 TOPS_AG_047 TOPS_AG_711 TOPS_AG_581 TOPS_AG_020 TOPS_AG_056 TOPS_AG_031 TOPS_AG_157 TOPS_AG_432&lt;/td&gt;
&lt;td&gt;
&lt;pre&gt;&lt;code&gt; 16768
18422
14121
14982
17595
18243
13139
15894
11880
7546
14900
&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;pre&gt;&lt;code&gt; 13324
14641
11593
12317
14532
15103
10913
13312
9993
6666
13440
&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;pre&gt;&lt;code&gt; 20.54
20.52
17.90
17.79
17.41
17.21
16.94
16.25
15.88
11.66
9.80
&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;</text></root>

And the output it gives is also the same.

 

5 - Then your Select Codes step runs and fails - split(last(xpath(outputs('XML'), '//tbody/tr/td/text()')), ' ')trim(item()).

Any help would be much appreciated - thank you so much!

grantjenkins
Super User
Super User

@ianwuk In Step 4 you should be using the following expression to convert to XML.

 

xml(concat('<table>', slice(outputs('Compose')?['text'], indexOf(outputs('Compose')?['text'], '<tbody>'))))

 

We don't convert to JSON first as it's already in XML format. We just need to convert to XML so that Power Automate knows to treat is as XML.


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.
ianwuk
Post Patron
Post Patron

@grantjenkins Thank you very much for replying.

I get a new error now, not sure what is happening now.

Here is my flow, up until the point it fails:

ianwuk_0-1673857558410.png


Compose - 

body('Get_message_details')?['attachments'][0]?['content'] 

ianwuk_1-1673857690285.png

XML (Compose) -

xml(concat('<table>', slice(outputs('Compose')?['text'], indexOf(outputs('Compose')?['text'], '<tbody>'))))
 
This is where it fails, with the error:
 
Unable to process template language expressions in action 'XML' inputs at line '0' and column '0': 'The template language expression 'xml(concat('<table>', slice(outputs('Compose')?['text'], indexOf(outputs('Compose')?['text'], '<tbody>'))))' cannot be evaluated because property 'text' cannot be selected. Property selection is not supported on values of type 'String'.
 
What am I doing wrong here?  Do you know?
 
Thanks so much!

For your Compose can you use the following expression:

 

body('Get_message_details')?['attachments'][0]?['content']?['text']

 

Then for your XML:

 

xml(concat('<table>', slice(outputs('Compose'), indexOf(outputs('Compose'), '<tbody>'))))

 


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.

Thank you for always replying @grantjenkins 

I updated both the Compose and XML steps, it now seems to fail at the updated Compose step and never gets to the updated XML step, with this error:

Unable to process template language expressions in action 'Compose' inputs at line '0' and column '0': 'The template language expression 'body('Get_message_details')?['attachments'][0]?['content']?['text']' cannot be evaluated because property 'text' cannot be selected. Property selection is not supported on values of type 'String'.

Here is the updated flow.

ianwuk_0-1673923946660.png

ianwuk_1-1673923999998.png

Sorry for being such a pain, and thanks very much for all your help.





 

 

Helpful resources

Announcements

Power Platform Connections - Episode 6 | March 23, 2023

Episode Six of Power Platform Connections sees David Warner and Hugo Bernier talk to talk to Business Applications MVP Shane Young, alongside the latest news, product updates, and community blogs.    Use the hashtag #PowerPlatformConnects on social media for a chance to have your work featured on the show!        Show schedule in this episode:  0:00 Cold Open 00:24 Show Intro 01:02 Shane Young Interview 22:00 Blogs & Articles 22:20 Integrate FullCalendar.io with Power Pages 23:50 Text Data 25:15 Zero to Hero Power Apps Saga 25:44 Parent Hub Association 26:33 Using Custom Values for OneNote Power Automate References​ 28:04 ​Dynamics Power Israel 28:44 Create Beautiful Canvas Apps in Dataverse for Teams ​ 30:36 Outro & Bloopers  Check out the blogs and articles featured in this week’s episode:   https://francomusso.com/integrate-fullcalendar-io-with-power-pages-from-json-basics-to-advanced-outp... @crmbizcoach https://yerawizardcat.com/text/ @YerAWizardCat www.fromzerotoheroes.com/mentorship ​ @thevictordantas https://www.expiscornovus.com/2023/03/16/parent-hub-association/ ​ @Expiscornovus https://lindsaytshelton.com/2023/03/15/the-painful-process-of-custom-values-for-onenote-power-automa... @lshelton_Tech https://never-stop-learning.de/create-beautiful-canvas-apps-in-dataverse-for-teams/ @MMe2K    Action requested: Feel free to provide feedback on how we can make our community more inclusive and diverse.  This episode premiered live on our YouTube at 12pm PST on Thursday 23rd March 2023.  Video series available at Power Platform Community YouTube channel.    Upcoming events:  Business Applications Launch – April 4th – Free and Virtual! M365 Conference - May 1-5th - Las Vegas Power Apps Developers Summit – May 19-20th - London European Power Platform conference – Jun. 20-22nd - Dublin Microsoft Power Platform Conference – Oct. 3-5th - Las Vegas  Join our Communities:  Power Apps Community Power Automate Community Power Virtual Agents Community Power Pages Community  If you’d like to hear from a specific community member in an upcoming recording and/or have specific questions for the Power Platform Connections team, please let us know. We will do our best to address all your requests or questions.   

Announcing | Super Users - 2023 Season 1

Super Users – 2023 Season 1    We are excited to kick off the Power Users Super User Program for 2023 - Season 1.  The Power Platform Super Users have done an amazing job in keeping the Power Platform communities helpful, accurate and responsive. We would like to send these amazing folks a big THANK YOU for their efforts.      Super User Season 1 | Contributions July 1, 2022 – December 31, 2022  Super User Season 2 | Contributions January 1, 2023 – June 30, 2023    Curious what a Super User is? Super Users are especially active community members who are eager to help others with their community questions. There are 2 Super User seasons in a year, and we monitor the community for new potential Super Users at the end of each season. Super Users are recognized in the community with both a rank name and icon next to their username, and a seasonal badge on their profile.    Power Apps  Power Automate  Power Virtual Agents  Power Pages  Pstork1*  Pstork1*  Pstork1*  OliverRodrigues  BCBuizer  Expiscornovus*  Expiscornovus*  ragavanrajan  AhmedSalih  grantjenkins  renatoromao    Mira_Ghaly*  Mira_Ghaly*      Sundeep_Malik*  Sundeep_Malik*      SudeepGhatakNZ*  SudeepGhatakNZ*      StretchFredrik*  StretchFredrik*      365-Assist*  365-Assist*      cha_cha  ekarim2020      timl  Hardesh15      iAm_ManCat  annajhaveri      SebS  Rhiassuring      LaurensM  abm      TheRobRush  Ankesh_49      WiZey  lbendlin      Nogueira1306  Kaif_Siddique      victorcp  RobElliott      dpoggemann  srduval      SBax  CFernandes      Roverandom  schwibach      Akser  CraigStewart      PowerRanger  MichaelAnnis      subsguts  David_MA      EricRegnier  edgonzales      zmansuri  GeorgiosG      ChrisPiasecki  ryule      AmDev  fchopo      phipps0218  tom_riha      theapurva  takolota     Akash17  momlo     BCLS776  Shuvam-rpa     rampprakash   ScottShearer     Rusk   ChristianAbata     cchannon   Koen5     a33ik        AaronKnox        Matren        Alex_10        Jeff_Thorpe        poweractivate        Ramole        DianaBirkelbach        DavidZoon        AJ_Z        PriyankaGeethik        BrianS        StalinPonnusamy        HamidBee        CNT        Anonymous_Hippo        Anchov        KeithAtherton        alaabitar        Tolu_Victor        KRider        sperry1625        IPC_ahaas      zuurg     rubin_boer     cwebb365       If an * is at the end of a user's name this means they are a Multi Super User, in more than one community. Please note this is not the final list, as we are pending a few acceptances.  Once they are received the list will be updated. 

Microsoft Power Platform | March 2023 Newsletter

Welcome to our March 2023 Newsletter, where we'll be highlighting the great work of our members within our Biz Apps communities, alongside the latest news, video releases, and upcoming events. If you're new to the community, be sure to subscribe to the News & Announcements and stay up to date with the latest news from our ever-growing membership network who find real "Power in the Community".        LATEST NEWS Power Platform Connections Check out Episode Five of Power Platform Connections, as David Warner II and Hugo Bernier chat with #PowerAutomate Vice President, Stephen Siciliano, alongside reviewing out the great work of Vesa Juvonen, Waldek Mastykarz, Maximilian Müller, Kristine Kolodziejski, Danish Naglekar, Cat Schneider, Victor Dantas, and many more.       Use the hashtag #PowerPlatformConnects on social media for a chance to have your work featured on the show!   Did you miss an episode?  Catch up now in the Community Connections Galleries Power Apps, Power Automate, Power Virtual Agents, Power Pages     Power Platform leading a new era of AI-generated low-code development.   **HOT OFF THE PRESS** Fantastic piece here by Charles Lamanna on how we're reinventing software development with Copilot in Power Platform to help you can build apps, flows, and bots with just a simple description! Click here to see the Product Blog         Copilot for Power Apps - Power CAT Live To follow on from Charles' blog, check out #PowerCATLive as Phil Topness gives Clay Wesener Wesner a tour of the capabilities of Copilot in Power Apps.           UPCOMING EVENTS   Modern Workplace Conference Check out the Power Platform and Microsoft 365 Modern Workplace Conference that returns face-to-face at the Espace St Martin in Paris on 27-28th March. The #MWCP23 will feature a wide range of expert speakers, including Nadia Yahiaoui, Amanda Sterner, Pierre-Henri, Chirag Patel, Chris Hoard, Edyta Gorzoń, Erika Beaumier, Estelle Auberix, Femke Cornelissen, Frank POIREAU, Gaëlle Moreau, Gilles Pommier, Ilya Fainberg, Julie Ecolivet, Mai-Lynn Lien, Marijn Somers, Merethe Stave, Nikki Chapple, Patrick Guimonet, Penda Sow, Pieter Op De Beéck, Rémi Riche, Robin Doudoux, Stéphanie Delcroix, Yves Habersaat and many more.  Click here to find out more and register today!     Business Applications Launch 2023 Join us on Tuesday 4th April 2023 for an in-depth look into the latest updates across Microsoft Power Platform and Microsoft Dynamics 365 that are helping businesses overcome their biggest challenges today. Find out about new features, capabilities, and best practices for connecting data to deliver exceptional customer experiences, collaborating and creating using AI-powered capabilities, driving productivity with automation, and building future growth with today’s leading technology. Click Here to Register Today!       Power Platform Conference 2023 We are so excited to see you for the Microsoft Power Platform Conference in Las Vegas October 3-5th, 2023! But first, let's take a look below at some fun moments from MPPC 2022 in Orlando Florida. 2023 sees guest speakers such as Charles Lamanna, Heather Cook, Julie Strauss, Nirav Shah, Ryan Cunningham, Sangya Singh, and many more taking part, so why not click the link below to register for the #PowerPlatformConf today! Vegas, baby! Click Here to Register Today!      COMMUNITY HIGHLIGHTS Check out our top Super and Community Users reaching new levels!  These hardworking members are posting, answering questions, kudos, and providing top solutions in their communities.   Power Apps:  Super Users:  @WarrenBelz  |  @iAm_ManCat  Community Users: @LaurensM | @Rusk | @RJM07    Power Automate:   Super Users: @abm  | @Expiscornovus | @RobElliott  Community Users:  @grantjenkins | @Chriddle    Power Virtual Agents:   Super Users: @Expiscornovus | @Pstork1  Community Users: @MisterBates | @Jupyter123 | Kunal K   Power Pages: Super Users:  @OliverRodriguesOliverRodrigues | @Mira_Ghaly  Community Users: @FubarFubar | @ianwukianwuk  LATEST PRODUCT BLOG ARTICLES  Power Apps Community Blog  Power Automate Community Blog  Power Virtual Agents Community Blog  Power Pages Community Blog  Check out 'Using the Community' for more helpful tips and information:  Power Apps, Power Automate, Power Virtual Agents, Power Pages 

Register now for the Business Applications Launch Event | Tuesday, April 4, 2023

Join us for an in-depth look into the latest updates across Microsoft Dynamics 365 and Microsoft Power Platform that are helping businesses overcome their biggest challenges today.   Find out about new features, capabilities, and best practices for connecting data to deliver exceptional customer experiences, collaborating, and creating using AI-powered capabilities, driving productivity with automation—and building towards future growth with today’s leading technology.   Microsoft leaders and experts will guide you through the full 2023 release wave 1 and how these advancements will help you: Expand visibility, reduce time, and enhance creativity in your departments and teams with unified, AI-powered capabilities.Empower your employees to focus on revenue-generating tasks while automating repetitive tasks.Connect people, data, and processes across your organization with modern collaboration tools.Innovate without limits using the latest in low-code development, including new GPT-powered capabilities.    Click Here to Register Today!    

Check out the new Power Platform Communities Front Door Experience!

We are excited to share the ‘Power Platform Communities Front Door’ experience with you!   Front Door brings together content from all the Power Platform communities into a single place for our community members, customers and low-code, no-code enthusiasts to learn, share and engage with peers, advocates, community program managers and our product team members. There are a host of features and new capabilities now available on Power Platform Communities Front Door to make content more discoverable for all power product community users which includes ForumsUser GroupsEventsCommunity highlightsCommunity by numbersLinks to all communities Users can see top discussions from across all the Power Platform communities and easily navigate to the latest or trending posts for further interaction. Additionally, they can filter to individual products as well.   Users can filter and browse the user group events from all power platform products with feature parity to existing community user group experience and added filtering capabilities.     Users can now explore user groups on the Power Platform Front Door landing page with capability to view all products in Power Platform.      Explore Power Platform Communities Front Door today. Visit Power Platform Community Front door to easily navigate to the different product communities, view a roll up of user groups, events and forums.

Microsoft Power Platform Conference | Registration Open | Oct. 3-5 2023

We are so excited to see you for the Microsoft Power Platform Conference in Las Vegas October 3-5 2023! But first, let's take a look back at some fun moments and the best community in tech from MPPC 2022 in Orlando, Florida.   Featuring guest speakers such as Charles Lamanna, Heather Cook, Julie Strauss, Nirav Shah, Ryan Cunningham, Sangya Singh, Stephen Siciliano, Hugo Bernier and many more.   Register today: https://www.powerplatformconf.com/   

Users online (2,257)