Provision Custom Sharepoint List Using SharePoint Framework Development Model

SharePoint Framework is the new development model in which lots of work has been going on in the past year. It went to General Availability on Feb 23, 2017. It is a page and web part model that provides full support for client-side SharePoint development, easy integration with SharePoint data and support for open source tooling. With the SharePoint Framework, you can use modern web technologies and tools in your preferred development environment to build productive experiences and apps in SharePoint.

In a previous article, we saw how to set up the development environment for SharePoint Framework. We also saw the basic Hello World webpart creation and how to retrieve and display list items using SharePoint Framework. In this article, we will see how to Provision Custom SharePoint List using SharePoint Framework.

Create the Web part Project

We can create the directory, where we will be adding the solution, using the command given below.

md CustomList

Let’s move to the newly created working directory, using the command.

cd CustomList

SharePoint

We will then create the client Web part by running the Yeoman SharePoint Generator.

yo @microsoft/sharepoint

SharePoint

This will display the prompt, which we must fill up, to proceed with the project creation.

  • What is your solution name? : Set it to ‘CustomList’.

On pressing enter, we will be asked to chose the working folder for the project.

  • Where do you want to place your files- Use current folder.
  • What framework would you like to start with- Select “No javaScript web framework” for the time being, as this is a sample Web part.
  • What is your Webpart name- We will specify it as ‘CustomList ‘and press Enter
  • What is your Webpart description- We will specify it as ‘Custom List Created using SharePoint Framework’

    SharePoint

Yeoman has started working on the scaffolding of the project. It will install the required dependencies and scaffold the solution files for the ‘CustomList’ Web part, which will take some time to complete. Once completed, we will get a congratulations message.

SharePoint

Run Code  to create the scaffolding and open the project in Visual Studio Code

SharePoint

Edit the web part

Now let’s add the folder named ‘SharePoint’ to maintain the SharePoint files that will be deployed as a package.

SharePoint

Within the SharePoint folder lets add another sub folder named Assets.

SharePoint

We will be creating an xml file - elements.xml which will hold the information required to provision the list. Let’s create the first supporting xml file elements.xml.

SharePoint

Add the below list information to the elements.xml file which contains the list name and type. The feature Id ‘00bfea71-de22-43b2-a848-c05709900100’ refers to custom list.

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <Elements xmlns="http://schemas.microsoft.com/sharepoint/">  
  3.     <ListInstance FeatureId="00bfea71-de22-43b2-a848-c05709900100" Title="CustomList" Description="Custom List Created Using SharePoint Framework" TemplateType="100" Url="Lists/CustomList"> </ListInstance>  
  4. </Elements>  
SharePoint

 

Package and Deploy the Solution

Now let’s create the deployment package by running gulp serve command from the Node.js command prompt.

SharePoint

This will create the sppkg package in the solutions folder as shown below.

SharePoint

Take a note of the sppkg file url by opening it in File Explorer.

SharePoint

We will be uploading this package to the App Catalog in the next step.

SharePoint

Head over to the App Catalog and upload the package.

SharePoint

After upload, it will ask if we trust the package. Click on Deploy to add the solution.

SharePoint

If we refresh the App Catalog page we can see the uploaded solution.

SharePoint

Ensure that there are no errors for the uploaded package by checking the below columns. In case there are some errors, we won’t be able to add the solution to the site.

SharePoint

Now if we head over to the site, we can see the newly uploaded solution in the site contents.

SharePoint

Click on it to add the solution to the site.

SharePoint

This will add the solution to the site contents. At the same time, it will provision whatever site assets were deployed as part of it. In our case, it is a custom list with the name ‘Custom List’. We can see it from the Site contents as shown below.

SharePoint

The main solution files used in this section are uploaded in Microsoft TechNet gallery. Feel free to download it.

Summary

Thus, we saw how to create and deploy a custom list to SharePoint using SharePoint Framework development model

Up Next
    Ebook Download
    View all
    Learn
    View all