Microsoft 365 and SharePoint Online Cookbook
上QQ阅读APP看书,第一时间看更新

Creating a list using a built-in list template

In Chapter 2, Introduction to SharePoint Online, we saw how to create a custom list from scratch. In this chapter, we'll see how to create lists using predefined list templates. For our recipe, we will use theAnnouncements list template. You can use the Announcements list to easily share news, updates, and announcements about your department or organization. You can use the inbuilt rich text editor to add images, links, and rich formatting to these announcements. You can then add this list as a web part on the home page of your site so that the announcements are prominently visible to your site visitors. You can additionally set an expiration date for each announcement so that it drops off the list after that date.

We will now see how to use this list template to create a Marketing Announcementslist on our site.

Getting ready

You will need Edit, Design, or Full Control permissions in your site to be able to create lists.

How to do it...

To create a new list based on the Announcements template, follow these steps:

Browse to the site in which you would like to create the list.

Click the settings gear icon in the top-right corner.

Click Add an app,as shown in the following screenshot:

Search for the term Announcementin the Find an appsearch box.

Note that sites based on certain templates, such as the modern communications site, need an extra step for the additional list templates, such as the Announcements template, to show up. You will need to enable the Team Collaboration Listsfeature in the site for such templates to show up. Features in SharePoint are modules of functionality that can be enabled or activatedas needed. To enable thisfeature, browse to the Site Features page, as described in this support article: https://m365book.page.link/Activate-Features. Then, search for the text Team Collaboration Listsand click the Activate button next to it. You will now start seeing the additional list and library templates on the Add an apppage.

Click the Announcementssearch result.

Enter Marketing Announcements for the list name and click the Create button.

The name you enter while creating a list or a library is also used as the Uniform Resource Locator ( URL) to your list. For example, the list we just created would have the following URL: https://tenant-name.sharepoint.com/sites/Marketing/Marketing%20Announcements/.

For that reason, you should avoid entering spaces or other special characters when creating lists or libraries in SharePoint. Doing so will ensure that the URL for your list is clean and does not contain any special characters. In the preceding example, you would want to enter Marketing Announcements as the list name. This would create a list with the following URL: https://tenant-name.sharepoint.com/sites/Marketing/MarketingAnnouncements (without the %20 in the URL ).

Once the list is created, you can go back and rename it to add the spaces and special characters to it as desired ( Marketing Announcements in our example, with a space in between). Renaming the list after it's created does not change the URL of the list, and your users would still see the same clean URL that got generated while creating the list, at the same time benefiting from a more user-friendly title.

Congratulations! You just created a list using the Announcements list template in SharePoint.

How it works...

In addition to the ability to create lists from scratch, SharePoint also provides templates that you can use to create lists and libraries in your site. When you create a list or library using one of the existing templates, SharePoint will automatically create and configure predefined columns, views, and settings based on that template. As is, such lists and libraries are generally geared toward addressing very focused needs so that you can start using them right away. If required, however, you can also customize them to meet any specific needs that you may have.

As an example, the Marketing Announcements list that we just created comes with fields that let you create an announcement, giving it a title, body, expiration date, and—optionally—add file attachments to it. The next few recipes will show you how to further customize the Marketing Announcements list by adding new columns and creating custom views for it.

Finally, in addition to creating a list this way, you can also create a list based on the following:

Click on the New menu from the home page (or any other modern page) on your site and then click App, as shown in the following screenshot:

Similarly, you can click the New menu and then App from the Site contents page to be taken to the Apps you can add page. If you are not familiar with the Site contents page, you can view the Viewing site contents recipe in Chapter 2, Introduction to SharePoint Online, to see how to browse to it from your site.

There's more...

Just like the Announcements list template, SharePoint comes with multiple other inbuilt list and library templates. You can also create lists based on existing lists that you may have created within your site.

In this section, we will first see a brief list of the other such native list and library templates that SharePoint offers. We will then discuss a few advanced ways to export the list so that it can be recreated within your site, other sites in your organization, or even across organizations.

Inbuilt list and library templates

SharePoint comes with multiple inbuilt templates that you can use to quickly create lists and libraries with predefined capabilities. The following is a list of all such templates in SharePoint:

Please note that some lists and libraries may or may not be available depending on the configuration or type of your site. The type or configuration of your site also dictates the lists and libraries that automatically get created when you create your site.

For more information regarding the list templates listed previously, please view the Types of lists section at: https://m365book.page.link/List-Types. For more information regarding the library templates, please view the Types of libraries section at: https://m365book.page.link/library-types.

Saving a list as a template

In addition to using the inbuilt templates to create lists, you can also create lists based on existing lists that you may have already created within your site.

We saw how to create a new list that is based on an existing list as part of the How to do it... section in the Creating a list recipe in Chapter 2, Introduction to SharePoint Online. For the most part, you should be able to use it to recreate an existing list with its columns, views, and formatting. There are, however, a few limitations in that approach:

When selecting the source list, you will only see sites and lists that you have access to, via permissions. Consequently, you will not be able to see or create lists based on other lists that you do not have access to.

You will not be able to copy over data using this approach.

You will be unable to copy over any list settings that you may have changed from the defaults.

You cannot use this approach if you would like to automate the creation of certain predefined lists when provisioning new sites.

This is where some of the additional methods discussed in this recipe come in handy. Using these methods, your SharePoint admins, or others who have access to the existing list, can export it as a template and share it with you so that you can recreate a new list in your site based on that template. The one drawback of these methods is that you will require administrator or developer help to be able to use them to export and import your lists.

We will briefly discuss these additional methods to save existing lists as templates and then reuse them to create new lists. Note that you canreuse the exported list templates to not only recreate lists within the same site or other sites in your organization but even across organizations/tenants if you need to do so.

Exporting a list using site scripts

We discussed site designs and site scripts as part of the Custom provisioning using site designs and site scripts topic of the Creating a subsite recipe in Chapter 3,Working with Modern Sites in SharePoint Online.

We can use the Get-SPOSiteScriptFromList command to export the list as a script. For more details, go to the following link: https://m365book.page.link/Get-SPOSiteScriptFromList.

The Get-SPOSiteScriptFromList command is part of the SharePoint Online PowerShell module. You can read more about SharePoint Online PowerShell in the Powershellsection of the Appendix

Once the list is exported, you can import it to an existing site or make it part of a site's design, to be provisioned to a new site.

Remember that in addition to using PowerShell for site designs and site scripts, you can also use the Microsoft 365 representational state transfer (REST) application programming interface (API) to carry out the same tasks, as described here:https://m365book.page.link/SiteDesign-RestAPI.

Exporting a list using PnP

The PnP (short for Patterns and Practices) provisioning engine also gives us commands for exporting your lists as reusable templates.

You can read more about PnP in the SharePoint PnP topic of the Office development frameworks section of the Appendix.

You can use the Export-PnPListToProvisioningTemplate command to export the list, as described here: https://m365book.page.link/Export-PnPListToProvisioningTemplate.

You would then use the Apply-PnPProvisioningTemplate command to recreate the list in a new or existing site, as described here: https://m365book.page.link/Apply-PnPProvisioningTemplate.

You can read more about the PnP provisioning engine and the templating capabilities here: https://m365book.page.link/PnP-Provisioning-Engine.

Exporting a list using list settings

Finally, you can also use the Save list as template list setting to save a list as a template. To do so, browse to the List settings page, as described in the Viewing and changing list settings recipe later in this chapter. Then, click the Save list astemplate heading under the Permissions and Management heading.

If you are not seeing this option under list settings, your site administrator might need to allow Custom Script. Please refer to this article from Microsoft to enable Custom Script on your site: https://m365book.page.link/Custom-Script.

You can then enter the values on this screen, as shown in the following screenshot, and then click the OKbutton to save the list as a template:

You will now start seeing this list in the Add an appscreen, as shown in the following screenshot:

You can also download the list template file and use it to create lists on other sites. You can also read more about saving and using list templates here: https://m365book.page.link/Manage-list-templates.

See also

The Creating a list recipe in Chapter 2, Introduction to SharePoint Online

The There's more... section of the Creating a subsite recipe in Chapter 3, Working with Modern Sites in SharePoint Online

The SharePoint PnP topic in the Officedevelopment frameworks section of the Appendix