Recently, we have observed that save list as a template option is missing for Modern SharePoint Online site. Because of which many users are getting confuse on how to restore their existing list into another site which is mostly required and quite normal in terms of SharePoint. Save as s template was very handy option to copy list definition as well as to migrate it contents in some cases.
Modern SharePoint Online is missing save as a template option for SharePoint list.
We restore exiting lists or libraries for various reasons:
- To restore existing list(s) into another site collection because of similar requirements for restoring list definitions
- Sometimes, we create development and production site collection. We create several lists and libraries in development site and then after completion of development task, we again retore those lists and libraries into production.
- Sometimes, we retore list in same site collection with different name to reuse the existing list and modify or use as it is for another requirements.
- Some cases, we might need to restore into another tenant as well if we are working with third party or vendor for development or some purposes.
- In some cases, we use this option to migrate list or libraries contents
This is one of general requirement to restore the existing list and library. Since, missing save as a template option is missing in modern SharePoint, we have some alternative ways to accomplish the same restoring of list.
In this article, I will show you the different ways of restoring the list from existing in Modern SharePoint. So far, I have found 3 alternative ways
- Option 1: Create a new list from exiting list
- Option 2: By using PnP, save a modern list as template and restore
- Option 3: By enable custom script in SharePoint Online
Create a new list from Existing list
This option is quite fast, easy, user friendly and most recommended where you can create new list from exiting option from another site collection.
Firstly, we need to create a new list from Site contents as shown:
Open Destination Site collection -> Site Contents -> Click New -> Select List
Next, we will choose option from existing list as shown:
After selecting, from existing list, you will get option to choose site collection and list within that site collection as depicted:
Select Site collection from which you want to restore the list and the list. Then you will get option at add the list in current site collection as demonstrated:
You can give name, description, and option to show in site navigation as like creating new list.
This is how you can restore existing list template.
However, this option has some limitations which are listed below:
- Some lists might not be compatible which has lookup columns
- You cannot restore data
- Some legacy lists cannot be restored
- Some site collections are showing incompatible lists.
By using PowerShell, Save a modern list as a template
Using PowerShell, we can save a list as template in modern sites both in team and communication site including list definition and data.
For this option, you need to have PnP PowerShell installed in your pc. Link to install GitHub – pnp/PnP-PowerShell: SharePoint PnP PowerShell CmdLets
You need to run following PowerShell
$siteURL = "https://YourSite/sites/SiteCollectionName"
$listName = "listName"
$templateName = "listTemplate"
$path = “C:\Users\rijwa\Documents”
cd $path
Connect-PnPOnline -Url $siteURL
Get-PnPProvisioningTemplate -Handlers Lists -ListsToExtract $listName -Out ("{0}.xml" -f $templateName)
Add-PnPDataRowsToProvisioningTemplate -path ("{0}.xml" -f $templateName) -List $listName -Query '<view></view>'
Explanation
First, we are defining siteUrl, listName (list which we want to save as template), templateName and path variables with values.
Then connect to SharePoint online.
Connect-PnPOnline -Url $siteURL
At last, we are extracting list and data with these commands:
Get-PnPProvisioningTemplate -Handlers Lists -ListsToExtract $listName -Out ("{0}.xml" -f $templateName)
Add-PnPDataRowsToProvisioningTemplate -path ("{0}.xml" -f $templateName) -List $listName -Query '<view></view>'
Additionally, we can add filters in data query.
Now, we have saved the list as template. Second step is to add the template into destination site collection.
We can achieve this by running this PowerShell.
$siteURL = " https://YourSite/sites/SiteCollectionName2"
$templateName = "listTemplate"
$path = “C:\Users\rijwa\Documents”
cd $path
Connect-PnPOnline -Url $siteURL
Apply-PnPProvisioningTemplate -Path ("{0}.xml" -f $templateName)
This execution of command takes few minutes depending upon your list data.
After this, if we create a new list, we find this template in our site collection and we can restore the list.
By enable custom script in SharePoint Online
Another option (not recommended) is by enabling custom script through SharePoint Admin Centre or PowerShell.
You can login to SharePoint Admin Centre -> Setting -> classic setting page.
Additionally, we can enable for the specific site collection using below PowerShell script.
#Variables for Admin Center & Site Collection URL
$AdminCenterURL = "https://site-admin.sharepoint.com/"
$SiteURL="https://site.sharepoint.com/Sites/marketing"
#Connect to SharePoint Online
Connect-SPOService -url $AdminCenterURL -Credential (Get-Credential)
#Disable DenyAddAndCustomizePages Flag
Set-SPOSite $SiteURL -DenyAddAndCustomizePages $False
Note: To apply the changes for enabling custom scripting might take up to 24 hours.
After enabling the custom script, we will need to go to list settings, and in the above URL, just replace listedit.aspx with savetmpl.aspx manually to save list as a template.
Conclusion
In this article, we have learned about restoring the list from existing one. In modern SharePoint site, save as a template for list and library is missing because of which users are facing issue to restore them. In this article, I have shared three alternative ways of restoring list and library from existing one.