Table of contents
Result
The @-mentions are the tricky part in setting the comments. Also, you might not want to re-notify people when creating the new items.
Before (list source)
After (list destination)
Using Power Automate
It is important that you name the actions accordingly to you can simply copy and paste all code snippets to your flow. You can obviously change the names according to yours, if you know what you are doing. You can also download the flow as a ZIP at the bottom.
- Create a new instant flow with a manual trigger
- Add the action “Initialize variable”
- Change the action name to: “Initialize variable - strComment”
- Variable name: strComment
- Type: String
- Value: leave empty
- Add the Get items action
- Name this action: “Get items - all items copy from list”
- You can use top count to get more than 100 elements or pagination in the settings page
- For testing change the top count to a 5-10 to test functionality of the flow, or if you want to test specific items, you can also add a filter by query like “ID eq 2”. Without the quotation marks, you will get only the item with ID 2.
- Add the action “Apply to each”
- Set the value the value from your get items action in 3.
- Name it: “For each - item to copy”
- In this loop add the action “Send an HTTP request to SharePoint”
- Name it: “Send an HTTP request to SharePoint - get comments from source”
- Configure your website and the title of the list, you want to copy from. The title is the name of the list as it appears in the URL, when you navigate to it.
- Add an action to create the item in your new list
- Name: “Create item - in copy to list”
- Add your website, choose your list and add all necessary fields from the previous get items action in 3.
- Be aware that sometimes Power Automate will create a loop for you, even though we create one already in 4. Either you use it instead of our own, or move this action to the correct place leaving the automatically created loop empty. Delete the empty loop.
- Add the action “Apply to each”
- Name it: For each - comment of item
- Use the results of the comment get request as the value
- Add the acton “Set variable”
- Name it: Set variable - strComment to null
- Choose the strComment variable and set the value with an expression to null
- Now we needs to check if the comment we are working on inside the loop of 7. has at-mentions in it. If the length of the mentions part is 0 then there are no comment, if its bigger than 0 there is at least one mention. (mentions has the results array, which shows all mentions in your comment)
- Add the action “Condition”
- Name it: “Condition - if at mention present”
- Left side of condition expression:
- In the True path of “Condition - if at mention present”
- Add the action “Apply to each”
- As the value, insert this as an expression:
- Add a condition
- Name it: Condition - If current item contains at mention token
- Left side of condition expression:
- Operator: contains
- Right side of condition number: mention{
- In the true path of “Condition - If current item contains at mention token”
- Add a compose action:
- Name it: The index describes the position of the person in the mentions array and contains the name and email.
- Input as an expression:
- Add the action: Append to string variable
- Name it: Append to string variable - add clear name mention to string
- Variable: strComment
- Value as an expression and add one space in front of the expression:
- In the false path of “Condition - If current item contains at mention token”
- Add the action: Append to string variable
- Name it: Append to string variable - add plain text to string
- Variable: strComment
- Value as an expression and add one space in front of the expression:
- Add a compose action
- Name it: Compose - Save comment to set in variable
- Input paste as is in the box below:
- Add an action Set variable
- Name it: Set variable - strComment with token
- Variable: strComment
- Value as expression:
- In the False path of “Condition - if at mention present”
- Add action: Set Variable
- Name it: Set variable - strComment no at mention token
- Select strComment as the variable
- Set value to this, as is in the box below:
- After Condition - if at mention present”, add the action “Send an HTTP request to SharePoint”
- Name it: Send an HTTP request to SharePoint - Add comment to copied item
sort(body('Send_an_HTTP_request_to_SharePoint_-_get_comments_from_source')?['d']?['results'],'createdDate')
length(item()?['mentions']?['results'])
c. Operator: is greater than
d. Right side of condition number: 0
Usually when inserting an at-mention, you will have a space after. If somebody purposely removes that spaces, we wouldn't be able to split in the spaces. For the plain text it wouldn't matter.
split(replace(item()?['text'],'}','} '),' ')
Explanation: This is what the comment with an at-mention will be saved:
“Bitte prüfen @mention{0;} und dann mit @mention{1;} kommunizieren”. Inside those two at-mention string is a number in the first its 0 and in the second its 1. These are to index position of the mentions in another property of the comment.
item()
replace(replace(item(),'@mention{',''),'}','')
items('For_each_-_comment_of_item')?['mentions']?['results'][int(outputs('Compose_-_Get_mention_index_from_current_item'))]?['name']
item()
@{item()?['author']?['name']} (@{convertFromUtc(item()?['createdDate'],'W. Europe Standard Time','dd.MM.yyyy HH:mm')}): @{variables('strComment')}
outputs('Compose_-_Save_comment_to_set_in_variable')
@{item()?['author']?['name']} (@{convertFromUtc(item()?['createdDate'],'W. Europe Standard Time','dd.MM.yyyy HH:mm')}): @{item()?['text']}
Method: POST
Uri: _api/web/lists/getbytitle('Comments to')/items(@{outputs('Create_item_-_in_copy_to_list')?['body/ID']})/Comments()
Headers:
{
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose"
}
Body:
{
"__metadata": {
"type": "Microsoft.SharePoint.Comments.comment"
},
"text": "@{variables('strComment')}"
}
After describing this, I should have probably made a video about it. Well 🙂
Download the flow as a ZIP here
Import with the legacy feature from my flows in the maker portal and then proceed from there. Change all connections, sharepoint urls and list names according to your needs.
Thanks for reading! 💕