In this blog I will take you step by step to export list item with comments into excel (csv) file using power automate.
- We will begin with creating a cloud flow with trigger of your choice. I will be using manual trigger for this post.
- After trigger let’s initialize few variables that will be used later in the flow.
- Will use “Get items” action to get all list items for export.
- Let’s loop through each item to get comments through REST API because “Get Items” action will not provide comments, hopefully in future MSFT adds some support for this ๐
- REST API call to get a comment for each item
_api/web/lists/getbyid(‘ListId’)/items(ItemId)/comments - Compose comments to get the comment text
- Check if comments are empty and set ItemComments variable to “No Comments” value If there are no comments for current list item
- If comments exist then we will loop through each comment to check user mentions (e.g. @divyesh) and format comments string accordingly. Note: Each actions mentioned in an image are explained in following steps.
- First let’s reset ItemComments variable to null in “Yes” action block and start looping through comments to check for user mentions.
- For comments with no mentions set ItemComments variable to
” Comment Text – Commented by <UserEmail> on <CreatedDate>\n” as shown below.
Note: You can format string as per your requirement. - For comments with mentions we need to loop through it to find and replace each mentions with user email.
Note: Comments string will have numeric reference to mentions like @mention{0} so we have to replace them with respective username or email. For this instance I am replacing it with email and converting ASCII value to string character e.g. @mention{divyesh@test.com}. In simple terms 0 has been replaced by user email and ASCII values decoded back to it’s original string characters - After Apply to each loop action let’s append the newly formatted string to ItemComments variable
- Compose all comments
- We will use Select action to build rows for CSV file with formatted comments
- Loop through each rows and append that to array variable ExcelTableData
- REST API call to get a comment for each item
- Now use “Create CSV table” action to generate the CSV formatted output for “Create file” action in next step
- Create and store excel file on document library of your choice
- Open the excel file and you will comments in CSV file as shown below
Well exporting only list items in excel is simple and few steps, however with comments it little complex and long. Hopefully this article will be helpful.
Sharing is caring ๐
18 responses to “How to export list items with comments into excel/csv file using power automate?”
Do you have a video for this process?
LikeLike
Unfortunately, no, feel free to ask me any questions and I will try my best to answer. If needed I can connect with your over a call.
LikeLike
Can you describe the exact action or condition you chose for each step? I am not as familiar with Power Automate and it is hard to figure our. You relabeled each one so it is hard to figure out what each one is. Also the specifics of the input and output for each, or if you entered an expression. You don’t give enough details on some of the steps to figure out those expressions.
LikeLike
Also, if you export your flow to a package zip, I could possibly import and modify for my situation. Thanks.
LikeLike
Hi,
Sorry, I have been little swamped with other things. Please find the exported flow zip and let me know if you need anything else.
https://github.com/divkotadia/BlogArtifacts/blob/5c76d8050f645c4335aa90902a38d5c684bac2f0/Export_Excel_Test_WP_v1_20230914230927.zip
LikeLike
Hello! I’ve been trying to make this flow work, but right now I’m stuck at “Check mentions in comments”, everytime I get to this step it shows me the following error:
“Unable to process template language expressions for action ‘Check_mentions_in_comments’ at line ‘0’ and column ‘0’: ‘The template language expression ‘length(items(‘Loop_through_comments_to_build_comment_string’)?[‘mentions/results’])’ cannot be evaluated because property ‘mentions/results’ cannot be selected. Array elements can only be selected using an integer index. Please see https://aka.ms/logicexpressions for usage details.’.”
I thought that maybe I needed to reproduce the step of Compose comments that was used to create body/d/results, but that did not work.
Does every comment needs to have mentions to this flow to be able to work?
I’m not a native speaker, just a random manager trying to automate processes, sorry if it is hard to understand, thank you for the tutorial! ๐
LikeLike
Hi,
Sorry, I have been little swamped with other things. Please find the exported flow zip and let me know if you need anything else.
https://github.com/divkotadia/BlogArtifacts/blob/5c76d8050f645c4335aa90902a38d5c684bac2f0/Export_Excel_Test_WP_v1_20230914230927.zip
LikeLike
This is what I need!! This is great, however I’m stuck because while the Variable names are unique – it doesn’t explain the type of variable needed and an overall view of the flow. Would you be available for a Teams or Zoom call and help me through this?
LikeLike
Hi,
Sorry, I have been little swamped with other things. Please find the exported flow zip and let me know if you need anything else. Also, I would be happy connect over zoom call.
https://github.com/divkotadia/BlogArtifacts/blob/5c76d8050f645c4335aa90902a38d5c684bac2f0/Export_Excel_Test_WP_v1_20230914230927.zip
LikeLike
I have a list with multiple comments for each list item. Will your flow export all of those comments? When I run your flow I only get the first comment for each list item.
LikeLike
Thank you for highlighting the issue. I have fixed it and updated the zip file. Please use the given below updated copy and let me know if you still face any issues.
https://github.com/divkotadia/BlogArtifacts/blob/effec706a72a24f70247c3e95ef6ded4a139e357/Export_Excel_Test_WP_v1_20230914230927.zip
LikeLike
Still same issue. Have you uploaded the wrong file? I see the date is the same as previous file.
LikeLike
It is working for me. I have item with ID 2 and 4 that have multiple comments and exported excel has all comments.
Note that I have updated the “Append new comment to ItemComments” action under “Check mentions in comments” condition from “Set the variable value” to “Append value to string variable” for the fix.
Do let me know if you still face the issue.
LikeLike
Does not work for me either. We have a list with almost 1000 rows and the spreadsheet that gets created only has about 5 rows. Does not appear to loop through the entire list unfortunately, otherwise this is almost exactly what I need
LikeLike
Actually, it is getting the first 10 rows in the list. Is this somehow limited to only 10 rows? Is there a way to loop through the entire list even if it’s only 10 rows at a time?
Thank you.
LikeLike
Hi Eric,
Please remove “Top count” value from “Get Items” action. It is set to 10.
Regards,
Divyesh
LikeLike
Thank you, I am now having another issue where the @mentions do not work. For instance it should be @John Smith but it says @mention{0} instead. I’m not quite sure why this is and how to resolve it. We have sometimes 10+ comments on a single Sharepoint list item with multiple people mentioned in the comment so I would love to get this resolved. I created a thread on the poweruser forum but no one has been able to assist me yet – https://powerusers.microsoft.com/t5/Building-Flows/Export-Sharepoint-list-items-with-comments-into-CSV-file/td-p/2415823
Thanks!
LikeLike
HI Eric,
Did you try to import the solution given at following location to your environment and let me know if that works?
https://github.com/divkotadia/BlogArtifacts/blob/effec706a72a24f70247c3e95ef6ded4a139e357/Export_Excel_Test_WP_v1_20230914230927.zip
Regards,
Divyesh
LikeLike