Power Automate Flow
Move data from list to another List in Folder and Subfolders
In this article will explain how to move data from list to another list and save the data in the folders and subfolders by Power Automate Flow.
Step 1: Get Items from share point list as below:
Step 2: Initialize Variables
We should initialize the variables to help us to find the correct path of the list, folders, and subfolders.
- Here we are initializing variable for list Name
- Here we are initializing variables for subfolders assuming we have a static folder named for example 2022, So we should determine the subfolder dynamically as below:
- If assuming the flow will trigger monthly in first day of each month for example (2022-June-1)
we should format the value of the variable as this:
* formatDateTime(addDays(utcNow(),-1,'yyyy-MM-dd'),'MMMM')
In this format, if today 2022-June-1 will reduce the day 1 and format the date to month name to determine the folder name because we want to distribute the data per month, So the result will be (May).
- Here we should initialize variable to determine the full path of subfolder in SharePoint as below:
Put your code like this code below:
https://Contoso.com /sites/FT/lists/@{variables('ListName')}/2022/@{variables('Month')}
Note:
- 2022: Consider the Folder.
- @{variables('Month'): Consider the Subfolder.
Step 3: Send HTTP request to SharePoint
you should follow screenshot below to fill the parameters correctly:
- Fill the site address you want to move.
- Method POST.
- Fill in the URI this code (Change the parameter based on your parameters) _api/web/lists/GetByTitle('@{variables('ListName')}')/AddValidateUpdateItemUsingPath .
- Fill in the Header as screenshot.
- Fill in the body as below format :
{
"listItemCreateInfo": {
"FolderPath": {
"DecodedUrl": "@{variables('FolderAndSub')}"
},
"UnderlyingObjectType": 0
}, "formValues": [
{
"FieldName": "Title",
"FieldValue": "@{items('Apply_to_each')?['Title']}"
},
{
"FieldName": "Source",
"FieldValue": "@{items('Apply_to_each')?['Source/Id']}"
},
{
"FieldName": "Company",
"FieldValue": "@{items('Apply_to_each')?['Company/Value']}"
}
]
,
"bNewDocumentUpdate": false
}
Note: in the Field name put the name of column (Correct Name is important as SharePoint) and in the Field value
Item value that given from Get Items step
I found this pattern the easiest way to move the data and save the data in folders and subfolders dynamically.
Another Resources:
- Power Automate Documentation: https://docs.microsoft.com/en-us/power-automate/
- Microsoft Learning: https://docs.microsoft.com/en-us/learn/
Comments