How to export list items with comments into excel/csv file using power automate?

In this blog I will take you step by step to export list item with comments into excel (csv) file using power automate.

  1. We will begin with creating a cloud flow with trigger of your choice. I will be using manual trigger for this post.
  2. After trigger let’s initialize few variables that will be used later in the flow.
  3. Will use “Get items” action to get all list items for export.
  4. 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
  5. Now use “Create CSV table” action to generate the CSV formatted output for “Create file” action in next step
  6. Create and store excel file on document library of your choice
  7. 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?”

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

    Like

  2. 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! ๐Ÿ˜€

    Like

  3. 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?

    Like

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

    Like

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

      Like

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

    Like

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

    Like

Leave a comment

Design a site like this with WordPress.com
Get started