Hi
I am creating HTML table from array to post in teams.
This is what my array contains.
[
{
"id": "333333333333333sssssssssssssss,
"receivedDateTime": "2024-01-23T15:25:11+00:00",
"hasAttachments": true,
"subject": "Subject Email 1",
"attachments": [
{
"@odata.type": "#microsoft.graph.fileAttachment",
"lastModifiedDateTime": "2024-01-23T15:25:11+00:00",
"name": "Attachment File Name 1",
"size": 12739
},
{
"@odata.type": "#microsoft.graph.fileAttachment",
"lastModifiedDateTime": "2024-01-23T15:25:11+00:00",
"name": "Attachment File Name 2",
"size": 12739
}
]
},
{
"id": "333333333333333sssssssssssssss",
"receivedDateTime": "2024-01-23T15:24:50+00:00",
"hasAttachments": true,
"subject": "Subject Email 2",
"attachments": [
{
"@odata.type": "#microsoft.graph.fileAttachment",,
"lastModifiedDateTime": "2024-01-23T15:24:50+00:00",
"name": "Attachment File Name 1",
"size": 12739
},
{
"@odata.type": "#microsoft.graph.fileAttachment",,
"lastModifiedDateTime": "2024-01-23T15:24:50+00:00",
"name": "Attachment File Name 2",
"size": 12739
}
]
I am feeding this array into "From" field of my create HTML Table. then using Header and values fields it works for below ones.
EmailReceiveTime = Item()?['receivedDateTime']
EmailSubject = Item()?['subject']
But I also want to include Attachment file names regardless of how many attachments are there with each email (in this example its 2 emails and each email have two attachments)
Thanks for your response! Wow! It is amazing for the method @ManishSolanki post . I have learned a lot from it !!😆
Thanks both again!!!!
Best Regards,
Yueyun Zhang
Thanks @v-yueyun-msft , @ManishSolanki Both.
Manish's Solution saves me from Loop and adding extra steps. Wish i was able to figure out these long powerful expressions.
Hi @nwkhattak
Another efficient way is to use expression to combine the values of attachment names. Here is an example.
In this example, I have stored the input array in the compose action:
[
{
"id": "333333333333333sssssssssssssss",
"receivedDateTime": "2024-01-23T15:25:11+00:00",
"hasAttachments": true,
"subject": "Subject Email 1",
"attachments": [
{
"odata.type": "#microsoft.graph.fileAttachment",
"lastModifiedDateTime": "2024-01-23T15:25:11+00:00",
"name": "Attachment File Name 1",
"size": 12739
},
{
"odata.type": "#microsoft.graph.fileAttachment",
"lastModifiedDateTime": "2024-01-23T15:25:11+00:00",
"name": "Attachment File Name 2",
"size": 12739
}
]
},
{
"id": "333333333333333sssssssssssssss",
"receivedDateTime": "2024-01-23T15:24:50+00:00",
"hasAttachments": true,
"subject": "Subject Email 2",
"attachments": [
{
"odata.type": "#microsoft.graph.fileAttachment",
"lastModifiedDateTime": "2024-01-23T15:24:50+00:00",
"name": "Attachment File Name 1",
"size": 12739
},
{
"odata.type": "#microsoft.graph.fileAttachment",
"lastModifiedDateTime": "2024-01-23T15:24:50+00:00",
"name": "Attachment File Name 2",
"size": 12739
}
]
}
]
Next, use expression to combine the attachments names for a list item in "Create HTML table" action:
join(xpath(xml(json(concat('{"root":{"item":',item()?['attachments'],'}}'))),'//name//text()'),', ')
Pls use the same expression in your flow to get the desired result.
Output:
If this helps & solves your problem, please remember to give a 👍 and accept my solution as it will help others in the future.
Hi , @nwkhattak
Thanks for your sample json for test first ! And according to your description, you want to show the attachments file names in your HTML Table.
This is my test flow and the result in the email:
(1)The Compose action is used to create the test data :
(2)The "Initialize variable " action:
(3)The "Apply to each" action:
items('Apply_to_each')?['attachments']
item()?['name']
json(concat('[',items('Apply_to_each'),']'))
Item()?['subject']
Item()?['receivedDateTime']
body('Select')?[0]
(4)The last two actions:
replace(replace(replace(body('Create_HTML_table_2'),'<','<') ,''',string('''')) ,'>' , '>')
If this reply can help you , you can click mark this reply as solution (Accept solution) which can help more people, thanks in advance!
Best Regards,
Yueyun Zhang
WarrenBelz
146,552
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,928
Most Valuable Professional