Skip to main content

Provisioning list through SPFx solution

In this article, we are going to learn How to provision SharePoint assets with SPFx and How to provision multiple instance of assets with SharePoint Framework Solution(SPFx).
SharePoint Framework tool chain allows us to package and deploy SharePoint items with SPFx solution. We can also provision multiple list instances with SharePoint Framework solution.

Follow the steps mentioned below to provision list instance with the SharePoint framework solution:
1. Once you are ready with your SharePoint Framework solution.
2. Create folders for the SharePoint assets:
     A. Create folder with  "sharepoint" name to the root of the solution. 
     B. Create folder with "assets" name inside the "sharepoint" folder.
  

3.  To provision SharePoint assets to sites with SharePoint Framework(SPFx), we need to create the required xml files. 
    A. Create a file elements.xml in sharepoint\assets folder in your solution.
    B. Copy the below xml code to elements.xml file.
   
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Field ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Type="Text" Name="Title" DisplayName="$Resources:core,Title;" Required="FALSE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="Title" MaxLength="255" />
<Field Name="Email" ID="{0d135b70-fba0-4e81-ab02-fb144779d5af}" DisplayName="Email" Type="Text" />
<ContentType ID="0x010042D0C1C200A14B6887742B6344675C8B"
Name="Test List"
Group="SPFx Content Types"
Description="Test data">
<FieldRefs>
<FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" />
<FieldRef ID="{0d135b70-fba0-4e81-ab02-fb144779d5af}" />
</FieldRefs>
</ContentType>
<ListInstance
CustomSchema="schema.xml"
FeatureId="00bfea71-de22-43b2-a848-c05709900100"
Title="Test List"
Description="Test List"
TemplateType="100"
Url="Lists/Test List">
</ListInstance>
</Elements>
 
  C. Create a file schema.xml in sharepoint\assets folder in your solution.
  D.  Copy the below xml code to schema.xml file.
<List xmlns:ows="Microsoft SharePoint" Title="Test List" EnableContentTypes="TRUE" FolderCreation="FALSE" Direction="$Resources:Direction;" Url="Lists/Test List" BaseType="0" xmlns="http://schemas.microsoft.com/sharepoint/">
<MetaData> <ContentTypes> <ContentTypeRef ID="0x010042D0C1C200A14B6887742B6344675C8B" /> </ContentTypes> <Fields></Fields> <Views> <View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,objectiv_schema_mwsidcamlidC24;" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="AllItems.aspx"> <XslLink Default="TRUE">main.xsl</XslLink> <JSLink>clienttemplates.js</JSLink> <RowLimit Paged="TRUE">30</RowLimit> <Toolbar Type="Standard" /> <ViewFields> <FieldRef Name="LinkTitle"></FieldRef> <FieldRef Name="Email" /> </ViewFields> <Query> <OrderBy> <FieldRef Name="ID" /> </OrderBy> </Query> </View> </Views> <Forms> <Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" /> <Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" /> <Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" /> </Forms> </MetaData> </List>
4. Now there is need to made some changes into the package-solution.json.  Copy the below code and paste it  into your package-solution.json file and your file will look likes this.
{ 
 "$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json", 
"solution": {
   "version": "1.0.0.0",
    "includeClientSideAssets": true,
    "isDomainIsolated": false,
    "features": [{
      "title": "list-provision-solution",
      "description": "list-provision-solution",
      "id": "00000000-0000-0000-0000-000000000000",// Replace this with new guid    
      "version": "1.0.0.0",
      "assets": {
        "elementManifests": [
          "elements.xml"
        ],
        "elementFiles":[
          "schema.xml"
        ]
      }
    }]
   },
  "paths": {
    "zippedPackage": "solution/listprovisioning.sppkg"
  }
}
 
Now generate new using online tool and replace the ID.
6. bundle the solution using "gulp bundle" command.
7. Now package the solution using "package-solution" command and deploy it to your SharePoint site.

Provision multiple list instance with SharePoint Framework solution(SPFx)

To provision multiple instance of list, We will create two schema files for ex schema1.xml and
schema2.xml. We can create an schema file as i mentioned above. Also we need one elements.xml file.

Files will be created in assets folder under sharepoint folder.(sharepoint/assets)

 

1. Create elements.xml and schema files(schema1.xml and schema2.xml) inside the assets folder.
Two schema files
2. Once the schema files are created, We need to mentioned both the files in our elemenst.xml file.
3. Mention all the schema files in the package-solution.json.
In this way, You can provision multiple lists using SPFx solution.
For more details follow : https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/get-started/provision-sp-assets-from-package
Thanks!!!!  

Comments

Post a Comment

Popular posts from this blog

SPFx Interview Questions With Answers

In this article, we are going to discuss interview questions related to the SPFx (SharePoint Framework Development ). It will help you to prepare for the interview and in getting clarity on the core concepts of SPFx development. What is SPFx? SPFx, short for SharePoint Framework,  SPFx  allows us for client-side SharePoint development, we can easily connect with SharePoint data and it also supports for open source tools. What is the major difference between SPFx web part and the SharePoint app? Both the development model supports client-side development but the major difference between these two is that the SharePoint app(add-in) runs on the iframe. What you can build with SPFx? Using SPFx framework we can customize the SharePoint pages. We can build things mentioned below using the SharePoint Framework(SPFx). Web parts, Extensions, Adaptive Card, Library Component How many types of extensions we can create using SPFx? SPFx has three extension types: Application Customizers: U...

How to Upgrade SharePoint Web Parts to the Newest Version

Updating the SharePoint/SPFx web parts or other solution is very common requirement, Webparts we can add from the SharePoint store or can be uploaded by our organization. To update a SharePoint web part to the latest version, start by uploading the updated SPFx package to the App Catalog. Then, make sure to upgrade the web part on the site where it’s being used. In this blog will be discussing ways to upgrade both package from the SharePoint app store or the the custom uploaded from the organization Update the web part added from the SharePoint app store: Go to the tenant level app catalog site. Select the app which you want to upgrade. Once you select the app, go the top ribbon and select file and click on the "Upgrade Store App", updated version will be added on the appcatalog if the new version is available on the store. Note: If you built the custom webpart then upload it to the app catalog. Install the upgraded solution: Navigate to the site collection where you have ins...

SharePoint Framework SPFx Node Version Compatibility

How to check the compatibility between the SPFx version and the Node.js version The SharePoint Framework (SPFx) is a client-side development platform used to develop web parts and extensions for SharePoint. The SharePoint Framework (SPFx) is compatible with the Node.js versions. Existing SPFx solutions may have different SPFx versions as compared to the current solutions. To make the SPFx solution run, Node.js is required, and in this blog, I am sharing steps to check the compatible node module for SPFx.  Find the SPFx version from the solution:  Open the project solution and navigate to the "package.json" file. In package.json file you will find  "@microsoft/sp-core-library" key and value of this particular key is the version of the SPFx.       Ex:    "@microsoft/sp-core-library": "1.14.0" Another way to find the SPFx version is by command, open the command prompt and run the command mentioned below: npm ls -g --depth=0 @microsoft/generator-s...