“You have everything, get list template, create new list but it is creating a new list with the same name, if it already exists Power Automate won’t create a new one.”
As pointed out in the comments, the solution to create a new SharePoint list from an existing one can be extended. As it is now, it’ll always create the list with the same name. But if you use it within the same site, you can’t create multiple lists with the same name. In these situations you might need to define a new name for the list. And this article will show you how.
Change the list name
IMPORTANT Note: the request now returns the list name in a strange format, use the request in the original article!
As already shown in the original article, list name is one of the properties in the JSON. By default it’s the name of the source list, but it’s not fixed. If you change the value of that property, you can change the name of the new list.
It’s a similar approach as when you add the list to the navigation. You must take the content of the ‘actions’ object, and change it. When adding the navigation, you’re adding a new property. This time the property already exists, it’s the ‘listName’. Therefore, you can just change it using the setProperty(…) expression.
The setProperty(…) will take an object, find a property, and set it to the desired value, e.g.
setProperty(<actions>, 'listName', 'New list name')
Note: the <actions> part is just a simplified string, it’s not the real input.
Add it to the expression used to create a list (without navigation):
replace(replace(string(setProperty(body('Parse_JSON')?['actions'][0],'listName', 'New list name')),'\','\\'),'"','\"')
Or to the expression used to create a list including the navigation:
replace(replace(string(setProperty(addProperty(body('Parse_JSON')?['actions'][0],'addNavLink',true),'listName','New list name')),'\','\\'),'"','\"')
Summary
When you create a new SharePoint list from a template, Power Automate allows you to make some changes, e.g. the name. You just need to find the right property, add it if it’s missing (navigation) or change the value if it already exists (list name).
This solution is designed only for the new lists created from template, if you’d like to rename existing lists there’s a dedicated post.
Hi Tom, I was able to use the first solution to create the SP List using the source template but when I try to use the setProperty I am running into trouble. I am looking to use a variable called Events Calendar as the dynamic content for the new SP list name. My expression looks like this:
Body:
{“script”: “{\”actions\”:@{replace(replace(string(setProperty(body(‘Parse_JSON’)?[‘actions’][0],’listName’,variables(‘Events Calendar’))),’\’,’\\’),'”‘,’\”‘)}}”}
Not sure where I am going wrong… Any advice? Or is it possible to use dynamic content in this way?
Hello Gary,
you’re missing the [ and ] brackets around the replace(…) expression
{"script": "{\"actions\":[@{replace(replace(string(setProperty(body('Parse_JSON')?['actions'][0],'listName',variables('Events Calendar'))),'\','\\'),'"','\"')}]}"}
Thank you! Great info.
Dear Tom,
I have a list of roughly 100 existing lists that I would like to rename.
I am not trying to change the URL of the list, but just the name. I would like to automate the renaming process and therefore consider to write a flow using the replace and setProperty methods.
Do you have any experience with such a request and do you think the method you explain in your article for newly created lists woudl work for existing lists?
Kind regards.
Hello Patrick,
you can’t apply the solution from the article to rename existing lists. To rename them I’d use a configuration list and an HTTP request.
A configuration list with the site url, current list name and the new list name, similar to this post: https://tomriha.com/copy-files-between-multiple-sp-libraries-in-a-single-power-automate-flow/
A ‘Send HTTP request to SharePoint’ action in a loop that would take the entries from the configuration list and rename the lists one by one
Method:
POST
Uri:
_api/web/lists/getByTitle('currentListName')
Headers:
{
"X-HTTP-Method": "MERGE",
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose",
"IF-MATCH": "*"
}
Body:
{
"__metadata": {
"type": "SP.List"
},
"Title": "New Title"
}
Hi Tom,
great Work – thank you. Evertyhing works fine – until i use a Lookup Column in my source List.
Error: (addSPLookupFieldXml) is invalid. Parameter “targetListName” has an invalid value.
Do you know if there is a way to make it work with lookup columns?
ty
Patrick
we have the same problem. We build the flow like: https://tomriha.com/create-new-sharepoint-list-from-existing-sp-list-with-power-automate/
but we get the Error: (addSPLookupFieldXml)
last week worked the flow well and there were no problems
Hello Patrick,
I can imagine that renaming a list that’s referenced in a lookup field could cause an issue. In that case I’d try a more brute-force solution by replacing the list name everywhere, not only in the listName property with an additional replace(…), e.g.
{“script”: “{\”actions\”:@{replace(replace(replace(string(body(‘Parse_JSON’)?[‘actions’]), ‘name of the original list’, ‘name of new list’), ‘\’,’\\’),’”‘,’\”‘)}}”}
Thank you very much for a very good guide. I want to enter the content from the source list over to the new list. Do you have a guide for this as well? I’m trying now myself, but I can’t get hold of the new list created. Do you know how I can get the ID on the new list?
Hello Tonje,
the Id of the newly created list should be among the outputs of the list creation action – try to extract it from the output JSON as explained here: https://tomriha.com/get-data-from-http-response-without-parse-json-in-power-automate/. It’ll be probably something like: body(‘Send_an_HTTP_request_to_SharePoint_-_create_list’)?[‘d’]?[‘ExecuteTemplateScript’]?[‘results’][0]?[‘TargetId’]
Hi Tom,
kindly provide your support on below issue.
I am facing the issue while creating the list using the template in same site. my flow is showing the success, but list does not present on site. flow showing the “List with name Test_26_3_2023 already exists”.
1st http body :
{
“listUrl”: “https://.sharepoint.com/Lists/Test_26_3_2023/”
}
2nd http Body:
{“script”: “{\”actions\”:[@{replace(replace(string(setProperty(body(‘Parse_JSON’)?[‘actions’][0],’Test_26_3_2023′, ‘Test_26_3_2024′)),’\’,’\\’),'”‘,’\”‘)}]}”}
2nd http output :
{
“d”: {
“ExecuteTemplateScript”: {
“__metadata”: {
“type”: “Collection(Microsoft.SharePoint.Utilities.WebTemplateExtensions.SiteScriptActionResult)”
},
“results”: [
{
“ErrorCode”: -2130575342,
“Outcome”: “2”,
“OutcomeText”: “List with name Test_26_3_2023 already exists.”,
“Target”: null,
“TargetId”: null,
“Title”: “Create or update list \”Test_26_3_2023\””
}
]
}
}
}
Hello karthik,
I’d check the value that enters the 2nd HTTP request, to see what’s the actual input and if it replaced the list name correctly.
Hi Tom,
im using Following code in my HTTP Request Body to create the list and give it a name:
{“script”: “{\”actions\”:[@{replace(replace(string(setProperty(body(‘Parse_JSON’)?[‘actions’][0],’listName’,variables(‘ListName’))),’\’,’\\’),'”‘,’\”‘)}]}”}
but now im recieving following error
action 1 (createSPList) is invalid. The paramter “addNavLink”has an invalid value
clientRequestId: b4f187a5-6e67-4e30-b81c-76049dc9a235
serviceRequestId: b340b8a0-f0b3-6000-9697-cb7421e6a4d0
I dont know why this is happening espacially because i didnt even try to add it to Navigation
Thank you in Advance
Hello Maxim,
that seems like some issue on Microsoft side, I’m not sure whether it was fixed in the meantime.
Anyone know if there is any way around that nav link error yet. I’ve got my flow to same point as Maxim above but kind of stuck now. :O(
Hello Stephen,
it seems there was a change in the request on Microsoft side and the addNavLink is already there by default, take a look on the original article where I updated the request: https://tomriha.com/create-new-sharepoint-list-from-existing-sp-list-with-power-automate/