In this example I will show how I used select action to pull up to 5 notes and 5 activities from a CRM 365 entity and email a user assigned a task with the notes included.

At the bottom of the email I wanted something like this:

in my example there was only one note but the code will pull up to five if available.

I will be focusing on an custom entity call Design Requests which has a timeline for notes and activities.

So the first action will be to list rows for notes but I am going to filter the results to only show the items related to the task and order them with the newest on top like so:

Here is the expression I used to only take the first 5:

take(outputs('List_rows_for_Notes_Regarding_DRF')?['body/value'], 5)

Click the icon that is a square with a T in it to switch to key value mode to paste the code.
I used this site to generate the html then added in the dynamic values.
(When you come back into this flow the formatting will be removed an it will say Enter a valid json. So read on and I will try to explain what is happening.)

"<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\"<tbody><tr><td style=\"width: 50%; text-align: center;\">@{item()?['subject']}</td><td style=\"width: 50%; text-align: center;\">@{item()?['notetext']}</td></tr></tbody></table>"

Here is the invalid json code:

<table style="border-collapse: collapse; width: 100%;" border="1"<tbody><tr><td style="width: 50%; text-align: center;">@{item()?['subject']}</td><td style="width: 50%; text-align: center;">@{item()?['notetext']}</td></tr></tbody></table>

Basically you need to escape any double quote (“) by putting a backslash (\) in front like so:

<table style=\”border-collapse

After doing that you need to enclose ALL of the code with double quotes (“) so the beginning and end will have a ” then the JSON should be valid and you can add in any dynamic values

To create the dynamic values use this format:

@{item()?['EnterTheItemYouWantHere']}

Let’s say for example there is a column called description and that in the info I want in the grid. I will create a compose action and select that dynamic content then peek at the code.

In my example you should notice something interesting. The dynamic content name says description but the code says notetext

 

That is the information we will use in the item formula above so it will look like this:

@{item()?['notetext']}

Once you define all the variables you want it will look similar to this:

The above line of code is basically one row in the html table and it will repeat through the array 5 times outputting any content each time to create 5 rows if available

The last step though is to join the items with div like so:

I then repeated the above steps for the activities table and created a new action to deliver the email

At the bottom of the email I specified the output of Join under the related title:

The final result is below (on the left is an example email and on the right is the information in CRM)
You could go a step further and hyperlink each activity to link to the item in CRM but that would be for another day
Hope this helps someone and let me know if you have any questions

 

Reference:
https://365corner.pl/2021/04/21/power-automate-select-vs-append-to-string/