I am tasked with creating a system that copies a series of folders and subfolders. I got the system to copy these folders but need to rename the main folder name to the project number and also rename the onenote file inside of that folder. Does anyone know what logic to apply to this or even info that can help program this in powerautomate? I have attached a photo of the system and highlighted the parts I need to rename.
Hi @zajacjos,
If you want to create subfolders you can use this FolderStructureArray value instead:
[
"1.Proposal",
"1.Proposal/0_Obsolete",
"1.Proposal/v1",
"2.Quote",
"3.Purchase Order"
]
Hi @zajacjos,
I think you made a typo in the Send an HTTP request URI fields.
It should be _api/web/GetFolderByServerRelativeUrl not _api/web/GetFolderByRelativeUrl
Also is there a way to use the array you helped me to create to add subfolders to 1.Proposal ? I need this structure and realized that since I stopped copying the the template that it no longer gets created.
I moved the OneNote so it followed the same folder structure as you I believe this fixed the copy problem but the next step is either pointing incorrectly or I missed something
this is the URI being outputted and the file structure seems off: _api/web/GetFolderByRelativeUri('/sites/automation/Project Folders/2088_test/XXXX_Project Description')/ListItemAllFields
Hi @zajacjos,
In the setup I shared the OneNote is stored in the root of the library.
If it is located in a different place in your setup you should select the correct location of the OneNote folder for the Folder to Copy field value. You can select it via that folder icon on the right hand side.
To clarify. This was the setup I used.
And this was the end result for a project with number PRJ-001 and a title Test
I am confused with the copy folder address
This is the address I used but feel like its incorrect
Can you explain how I get the correct destination address as I keep getting errors with step 7 and 8
Hi @zajacjos,
Here is a step-by-step walkthrough of the setup, if that helps?
I will update this post with some screenshots as well.
1. When an item is created
a. Use the Site Address you want
b. Use your Project Numbers list
2. Add Initialize variable action
a. Use ProjectNumber as Name
b. Select Type String
c. Use Project# as value
3. Add Initialize variable action
a. Use Title as Name
b. Select Type String
c. Use Title as value
4. Add Initialize variable action
a. Use FolderStructureArray as Name
b. Select Type Array
c. Use an array like below as value
[
"1.Proposal",
"2.Quote",
"3.Purchase Order"
]
5. Add an apply to each.
a. Use the FolderStructureArray in the Select an output from previous steps
6. Add an Create new folder (within the apply to each)
This will create the folder structure based on the items of the array
a. Select Site Address
b. Select the Library, Project Folders
c. Use the following value for the Folder Path
/@{variables('ProjectNumber')}_@{variables('Title')}/@{item()}
7. Add a Copy Folder action
This action only copies the OneNote to the new Project Folder location
a. Select Current Site Address
b. Select the Location of the OneNote template
/Project Folders/Template OneNote
c. Select Destination Site Address
d. Select the Destination of the OneNote tempalte
/Project Folders/@{variables('ProjectNumber')}_@{variables('Title')}
8. Add a Send an HTTP request
This action is to retrieve the Odata type value for the next action
a. Select the Site Address
b. Use the GET Method
c. Use the following URI
_api/web/GetFolderByServerRelativeUrl('/sites/automation/@{outputs('Copy_folder')?['body/Path']}')/ListItemAllFields
d. Use the following Headers
{
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose"
}
9. Add a Send an HTTP request
With this action we rename the OneNote folder
a. Select the Site Address
b. Use the POST Method
c. Use the following URI
_api/web/GetFolderByServerRelativeUrl('/sites/automation/@{outputs('Copy_folder')?['body/Path']}')/ListItemAllFields
d. Use the following Headers
{
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose",
"If-Match": "*",
"X-HTTP-Method": "MERGE"
}
e. Use the following Body
{
"__metadata": {
"type": "@{body('Send_an_HTTP_request_to_SharePoint')['d']['__metadata']['type']}"
},
"Title": "@{variables('ProjectNumber')}_@{variables('Title')}",
"FileLeafRef": "@{variables('ProjectNumber')}-@{variables('Title')}"
}
I made some updates and now no file appears in project folders anymore! Are you allowed to accept tips? I really appreciate the help, I didnt even think it would be possible to update it.
Hi @zajacjos,
Below are a couple of thing which I would change for the setup in screenshots of page1, page2 and page3.
1. Change Project Number and Title variables to Type String.
2. Remove the Folder Name from the List or Library field. Remove the Library name from the Folder Path field.
3. Update the RelativeUrl in the Uri field of both Send an HTTP request actions to use your automation site and not the site from my example (PowerUsers). Correct the small typo of the Content-Type header. The word verbos is missing an e. (should be verbose).
here is the final page and result
WarrenBelz
146,537
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,908
Most Valuable Professional