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

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

19 REPLIES 19
CFernandes
Most Valuable Professional
Most Valuable Professional

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 Partisan
Post Partisan

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.
CFernandes
Most Valuable Professional
Most Valuable Professional

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

ianwuk
Post Partisan
Post Partisan

@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 Partisan
Post Partisan

@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 Partisan
Post Partisan

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 Partisan
Post Partisan

@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 Partisan
Post Partisan

@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 Partisan
Post Partisan

@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 Partisan
Post Partisan

@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.





 

 

Samruddhi
New Member

Hii,
Can I know how to extract/fetch specific values from one json object and replace those values in another objects value.
Example: I'm fetching an id value from an object (ids can be multiple) and want to replace those id's in another objects id.
I'm doing this using Power Automate workflow . Please help me out with solution.

Samruddhi_1-1682583115742.png

 

 

@grantjenkins

Hope you are good.

I was wondering if you could possibly spare a few moments to help me again with this flow.

I am not sure if I have broken it or not and I also want to modify it slightly.

Here is what I have:

1 - A new message comes into the Teams channel I selected
2 - Compose -  

triggerBody()?['attachments'][0]['content']
3 - XML -  
xml(json(concat('{"root": ', triggerBody()?['attachments'][0]['content'], '}')))
4 - Condition (IF True) - 
length(xpath(outputs('XML'), '//sections/facts[contains(name, "Monitor status") and contains(value, "DOWN")]')) 
5 - Reply with a message to a message ID to the Team and Channel I select - trigger(Outputs()?['body/id']

My questions are:

1 - Is this flow now correct to automatically reply to a message that comes in where the Monitor Status is DOWN?  I think so, but I just wanted to confirm.

2 - I want to put a 10 minute delay after step 4, so that, the message reply is only triggered if the original message that contained alert whose Monitor Status: DOWN has not had another Teams message come in where that same alert status has changed to Monitor Status: UP.

How would I do this?

Can I just add a ten minute delay followed by 
length(xpath(outputs('XML'), '//sections/facts[contains(name, "Monitor status") and contains(value, "UP")]'))?

What I don't understand is how to track somehow that same alert in a different message, if that makes sense?

Any help is very much appreciated.  Thank you.


 

Helpful resources

Announcements

Exclusive LIVE Community Event: Power Apps Copilot Coffee Chat with Copilot Studio Product Team

It's time for the SECOND Power Apps Copilot Coffee Chat featuring the Copilot Studio product team, which will be held LIVE on April 3, 2024 at 9:30 AM Pacific Daylight Time (PDT).     This is an incredible opportunity to connect with members of the Copilot Studio product team and ask them anything about Copilot Studio. We'll share our special guests with you shortly--but we want to encourage to mark your calendars now because you will not want to miss the conversation.   This live event will give you the unique opportunity to learn more about Copilot Studio plans, where we’ll focus, and get insight into upcoming features. We’re looking forward to hearing from the community, so bring your questions!   TO GET ACCESS TO THIS EXCLUSIVE AMA: Kudo this post to reserve your spot! Reserve your spot now by kudoing this post.  Reservations will be prioritized on when your kudo for the post comes through, so don't wait! Click that "kudo button" today.   Invitations will be sent on April 2nd.Users posting Kudos after April 2nd at 9AM PDT may not receive an invitation but will be able to view the session online after conclusion of the event. Give your "kudo" today and mark your calendars for April 3, 2024 at 9:30 AM PDT and join us for an engaging and informative session!

Tuesday Tip: Unlocking Community Achievements and Earning Badges

TUESDAY TIPS are our way of communicating helpful things we've learned or shared that have helped members of the Community. Whether you're just getting started or you're a seasoned pro, Tuesday Tips will help you know where to go, what to look for, and navigate your way through the ever-growing--and ever-changing--world of the Power Platform Community! We cover basics about the Community, provide a few "insider tips" to make your experience even better, and share best practices gleaned from our most active community members and Super Users.   With so many new Community members joining us each week, we'll also review a few of our "best practices" so you know just "how" the Community works, so make sure to watch the News & Announcements each week for the latest and greatest Tuesday Tips!     THIS WEEK'S TIP: Unlocking Achievements and Earning BadgesAcross the Communities, you'll see badges on users profile that recognize and reward their engagement and contributions. These badges each signify a different achievement--and all of those achievements are available to any Community member! If you're a seasoned pro or just getting started, you too can earn badges for the great work you do. Check out some details on Community badges below--and find out more in the detailed link at the end of the article!       A Diverse Range of Badges to Collect The badges you can earn in the Community cover a wide array of activities, including: Kudos Received: Acknowledges the number of times a user’s post has been appreciated with a “Kudo.”Kudos Given: Highlights the user’s generosity in recognizing others’ contributions.Topics Created: Tracks the number of discussions initiated by a user.Solutions Provided: Celebrates the instances where a user’s response is marked as the correct solution.Reply: Counts the number of times a user has engaged with community discussions.Blog Contributor: Honors those who contribute valuable content and are invited to write for the community blog.       A Community Evolving Together Badges are not only a great way to recognize outstanding contributions of our amazing Community members--they are also a way to continue fostering a collaborative and supportive environment. As you continue to share your knowledge and assist each other these badges serve as a visual representation of your valuable contributions.   Find out more about badges in these Community Support pages in each Community: All About Community Badges - Power Apps CommunityAll About Community Badges - Power Automate CommunityAll About Community Badges - Copilot Studio CommunityAll About Community Badges - Power Pages Community

Tuesday Tips: Powering Up Your Community Profile

TUESDAY TIPS are our way of communicating helpful things we've learned or shared that have helped members of the Community. Whether you're just getting started or you're a seasoned pro, Tuesday Tips will help you know where to go, what to look for, and navigate your way through the ever-growing--and ever-changing--world of the Power Platform Community! We cover basics about the Community, provide a few "insider tips" to make your experience even better, and share best practices gleaned from our most active community members and Super Users.   With so many new Community members joining us each week, we'll also review a few of our "best practices" so you know just "how" the Community works, so make sure to watch the News & Announcements each week for the latest and greatest Tuesday Tips!   This Week's Tip: Power Up Your Profile!  🚀 It's where every Community member gets their start, and it's essential that you keep it updated! Your Community User Profile is how you're able to get messages, post solutions, ask questions--and as you rank up, it's where your badges will appear and how you'll be known when you start blogging in the Community Blog. Your Community User Profile is how the Community knows you--so it's essential that it works the way you need it to! From changing your username to updating contact information, this Knowledge Base Article is your best resource for powering up your profile.     Password Puzzles? No Problem! Find out how to sync your Azure AD password with your community account, ensuring a seamless sign-in. No separate passwords to remember! Job Jumps & Email Swaps Changed jobs? Got a new email? Fear not! You'll find out how to link your shiny new email to your existing community account, keeping your contributions and connections intact. Username Uncertainties Unraveled Picking the perfect username is crucial--and sometimes the original choice you signed up with doesn't fit as well as you may have thought. There's a quick way to request an update here--but remember, your username is your community identity, so choose wisely. "Need Admin Approval" Warning Window? If you see this error message while using the community, don't worry. A simple process will help you get where you need to go. If you still need assistance, find out how to contact your Community Support team. Whatever you're looking for, when it comes to your profile, the Community Account Support Knowledge Base article is your treasure trove of tips as you navigate the nuances of your Community Profile. It’s the ultimate resource for keeping your digital identity in tip-top shape while engaging with the Power Platform Community. So, dive in and power up your profile today!  💪🚀   Community Account Support | Power Apps Community Account Support | Power AutomateCommunity Account Support | Copilot Studio  Community Account Support | Power Pages

Super User of the Month | Chris Piasecki

In our 2nd installment of this new ongoing feature in the Community, we're thrilled to announce that Chris Piasecki is our Super User of the Month for March 2024. If you've been in the Community for a while, we're sure you've seen a comment or marked one of Chris' helpful tips as a solution--he's been a Super User for SEVEN consecutive seasons!   Since authoring his first reply in April 2020 to his most recent achievement organizing the Canadian Power Platform Summit this month, Chris has helped countless Community members with his insights and expertise. In addition to being a Super User, Chris is also a User Group leader, Microsoft MVP, and a featured speaker at the Microsoft Power Platform Conference. His contributions to the new SUIT program, along with his joyous personality and willingness to jump in and help so many members has made Chris a fixture in the Power Platform Community.   When Chris isn't authoring solutions or organizing events, he's actively leading Piasecki Consulting, specializing in solution architecture, integration, DevOps, and more--helping clients discover how to strategize and implement Microsoft's technology platforms. We are grateful for Chris' insightful help in the Community and look forward to even more amazing milestones as he continues to assist so many with his great tips, solutions--always with a smile and a great sense of humor.You can find Chris in the Community and on LinkedIn. Thanks for being such a SUPER user, Chris! 💪 🌠  

Find Out What Makes Super Users So Super

We know many of you visit the Power Platform Communities to ask questions and receive answers. But do you know that many of our best answers and solutions come from Community members who are super active, helping anyone who needs a little help getting unstuck with Business Applications products? We call these dedicated Community members Super Users because they are the real heroes in the Community, willing to jump in whenever they can to help! Maybe you've encountered them yourself and they've solved some of your biggest questions. Have you ever wondered, "Why?"We interviewed several of our Super Users to understand what drives them to help in the Community--and discover the difference it has made in their lives as well! Take a look in our gallery today: What Motivates a Super User? - Power Platform Community (microsoft.com)

March User Group Update: New Groups and Upcoming Events!

  Welcome to this month’s celebration of our Community User Groups and exciting User Group events. We’re thrilled to introduce some brand-new user groups that have recently joined our vibrant community. Plus, we’ve got a lineup of engaging events you won’t want to miss. Let’s jump right in: New User Groups   Sacramento Power Platform GroupANZ Power Platform COE User GroupPower Platform MongoliaPower Platform User Group OmanPower Platform User Group Delta StateMid Michigan Power Platform Upcoming Events  DUG4MFG - Quarterly Meetup - Microsoft Demand PlanningDate: 19 Mar 2024 | 10:30 AM to 12:30 PM Central America Standard TimeDescription: Dive into the world of manufacturing with a focus on Demand Planning. Learn from industry experts and share your insights. Dynamics User Group HoustonDate: 07 Mar 2024 | 11:00 AM to 01:00 PM Central America Standard TimeDescription: Houston, get ready for an immersive session on Dynamics 365 and the Power Platform. Connect with fellow professionals and expand your knowledge. Reading Dynamics 365 & Power Platform User Group (Q1)Date: 05 Mar 2024 | 06:00 PM to 09:00 PM GMT Standard TimeDescription: Join our virtual meetup for insightful discussions, demos, and community updates. Let’s kick off Q1 with a bang! Leaders, Create Your Events!  Leaders of existing User Groups, don’t forget to create your events within the Community platform. By doing so, you’ll enable us to share them in future posts and newsletters. Let’s spread the word and make these gatherings even more impactful! Stay tuned for more updates, inspiring stories, and collaborative opportunities from and for our Community User Groups.   P.S. Have an event or success story to share? Reach out to us – we’d love to feature you!

Users online (5,328)