cancel
Showing results for 
Search instead for 
Did you mean: 

How to create SharePoint list or library using PnP provisioning template in Microsoft Flow, Azure Logic Apps or PowerApps

This article will show how to create a custom SharePoint list or library using PnP provisioning template. You can use this approach to create lists or libraries of any complexity in SharePoint. For example, you may want to create an employees list with a set of predefined columns for your team. We will do it below.

PnP template is an XML file that contains a description of SharePoint entities (lists, libraries, pages, etc.) that will be created. You can create own XML template for your SharePoint list or library. Then use the Provision PnP template to SharePoint action from Plumsail Actions to apply PnP templates to your SharePoint sites using Microsoft Flow or Azure Logic Apps.

If you are new to Plumsail Actions, follow this getting started instruction.

First of all, we need to create a PnP provisioning template for our list. Let us say we have the employees list:

new-employees-example-list.png

There are two ways to create a PnP template:

  1. Write a PnP template manually and provision a simple list - It is useful for simple lists without custom views or content types.
  2. Get a PnP template from an existing list and provision a complex list - It is useful for complex lists with content types, views, site columns.

You will find the description of both approaches below. Pick the one that you like more.

 

Write a PnP template manually and provision a simple list

This approach is useful for creation of simple lists or document libraries without custom content types, site columns, etc.

Please open this link to see example of a template for simple employees list. Let us review what you can change in the template.

 

<pnp:ListInstance> tag

<pnp:ListInstance> tag represents a list. You can change list title (Title) and list URL (Url). Also, if you want to create a document library, you need to change TemplateType to 101 instead of 100.

You can find all the available template types in the official Microsoft documentation.

 

<Field> tag

<pnp:Field> tag represents a column in your list. You can add new fields by adding new tags like this:

<pnp:Fields>
  <Field ID="{4512a091-1007-4cd9-900b-411f01f2b119}" DisplayName="Manager" Name="Manager" Type="Text"/>
  ...
</pnp:Fields>
  • DisplayName is a display name of the field.
  • Name is an internal name of the field.
  • Type represents a type of the field. You can find all the available types in this article.
  • ID is a unique ID of the field. You can put here unique GUID or fill it dynamically in your Microsoft Flow. See the example below.

 

<FieldRef> tag under <ViewFields>

<FieldRef> tag under <ViewFields> represents a field in a list view. If you want to add your new field in the list view, create the <FieldRef>tag for it:

<ViewFields>
  <FieldRef Name="Manager" />
  ...
</ViewFields>

For more information about tags available in PnP templates review PnP provisioning schema.

 

Example of Microsoft Flow

Copy and paste your template into Provision PnP template to SharePoint action in your Flow:

create-simple-list-pnp-flow-example.png

You need to replace all values for Field IDs using Microsoft Flow expressions like on the screenshot above. It will ensure that your fields will always have unique IDs.

This approach is useful when you want to create simple SharePoint lists or document libraries. If you have a complex list with many views you may consider another option with creating your template from an existing list using PowerShell. For more information read below.

 

Get a PnP template from an existing list and provision a complex list

PnP PowerShell allows you to execute various commands for manipulating SharePoint, including grabbing of a template from a SharePoint site.

First of all, you need to install PnP PowerShell. Follow the installation instruction. Then connect to your SharePoint site. Execute the command below and specify your own URL for the site where your Modern page is stored:

Connect-PnPOnline -Url "https://contoso.sharepoint.com/sites/mysite"

Unfortunately, there are no PnP PowerShell commands for getting a template from a single list. You could execute this command:

Get-PnPProvisioningTemplate -Out "template.xml" -Handlers Lists

But this command creates a template for all lists and libraries on your site. If it is your case, you can use the code above. Otherwise, you need a workaround.

The script below is the workaround. It will help you to get a template from a single list:

$listName = "Employees";
$outputTemplateFileName = "template.xml";
$template = Get-PnPProvisioningTemplate -OutputInstance -Handlers Lists
$listTemplate = $template.Lists | Where-Object { $_.Title -eq $listName }
$template.Lists.Clear()
$template.Lists.Add($listTemplate)
Save-PnPProvisioningTemplate -InputInstance $template -Out $outputTemplateFileName

This scripts gets a template for a single list. Let's take a closer look:

  • In the first line we specify title of the list. You need to replace "Employees" by the name of your list.
  • In the second line, we specify the location of the output template file. You can change "template.xml" to another path.
  • The rest of the code takes a template for all lists of the site. Then it removes all the lists except the one we need.

Once you executed the script, you will have the template for your specific list or document library.

Note: This script gets a template of a list without external references like content types, site columns, etc. If you need to include them into the template, you need to modify the PowerShell script or do it manually in the XML.

That is all. Now you can save the template file somewhere in your SharePoint and use this file as a template in the Provision PnP template to SharePoint action:

provision-pnp-template-to-sp.png

If you haven’t used Plumsail Actions yet, registering an account would be the first step. It is quite easy to get started.

This post was originally published here.

 

Meet Our Blog Authors
  • Experienced Consultant with a demonstrated history of working in the information technology and services industry. Skilled in Office 365, Azure, SharePoint Online, PowerShell, Nintex, K2, SharePoint Designer workflow automation, PowerApps, Microsoft Flow, PowerShell, Active Directory, Operating Systems, Networking, and JavaScript. Strong consulting professional with a Bachelor of Engineering (B.E.) focused in Information Technology from Mumbai University.
  • Encodian Owner / Founder - Ex Microsoft Consulting Services - Architect / Developer - 20 years in SharePoint - PowerPlatform Fan
  • Cambridge UK Power Platform User Group Leader, Technical evangelist and speaker. Always says yes to coffee! #LetsGetCoffee
  • Passionate #Programmer #SharePoint #SPFx #Office365 #MSFlow | C-sharpCorner MVP | SharePoint StackOverflow, Github, PnP contributor