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: Using the

How to register an app in SharePoint

In this article, we are going to learn how to register an app/add-in in SharePoint online. If you have created a Sharepoint provider-hosted add-in or other SharePoint solution and to access the SharePoint site or list using the app/add-in you need to register the add-in on SharePoint and to grant permission. Register app in SharePoint 1. Login into SharePoint and Navigate to register an app page. Use the URL mentioned below:          [Sitecollection URL]/_layouts/15/appregnew.aspx 2.  Once you navigate to the Register app page, a form will open. You need to fill all the fields on the form. Client Id and Client Secret  generated when we click on the generate button available next to the fields.  Title : Name of the add-in which you want to give. App Domain : Where your domain is hosted, for the local environment you can place             "www.localhost.com". Do not include HTTP or HTTPS in App Domain. Redirect URL :  Insert the redirect URL, for t

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