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

Popular posts from this blog

How to create list from template in sharepoint

In this article, we are going to learn how to create a list from list template or using(.stp) file or we can say create list from existing list. Once you save the list as a template, It appears into List template option under the web designer gallery on site setting page. Steps to create list from list template: 1 Move to the site setting section where you have saved the list template. 2. When you click on the List templates, you will redirect to the List template gallery and from the list template gallery. 3. Now click on the File in ribbon and click on the upload document. 4. Browse the location where your list template is downloaded. I am uploading the template of an address list. 5.  After browsing the template, now you can give the name what you want to give to the list template and click on save. 6. Now the list template file appears into the list template gallery. Now click on the gear  icon and click on the Add an app. 7. On clicking add an app,

Content editor web part missing in SharePoint/Modern SharePoint.

Media and content editor web part missing in SharePoint online. At Some Point, you need to add content editor web part into the modern site but the content editor web part did not appear on the page, to appear content editor web part on page you need to follow the below steps. 1 Log in as the SharePoint Global Administrator or SharePoint Administrator. 2.  Log in and navigate to your site collection ("https://xyz.sharepoint.com") and under the site settings activate the below features.   Site settings – site features – SharePoint Server Publishing .   Site Settings – Site Actions – Manage site features- SharePoint Server Publishing Infrastructure.                For this, you also need to enable Custom site scripts on your site collection(But In Modern SharePoint Its not recommended to enabling custom site scripting)  For this go to the  SharePoint Admin center – Settings -  Classic settings page (option mentioned on page)- Scroll the page you found an optio

Save site as template option in sharepoint online

In this article, we are going to learn about "save site as template option missing in sharepoint". When  you want  to replicate a site that you have already created and for this, you have to save site as template.  For this,  you go  on  Site setting   and then   move to  Site  action   but you did not  find  the option “ Save site as template ” option.    There are several reasons behind the missing of "save site as template" option, to get this option check options below mention.   Custom script is not allowed  on tenant   On the new office 365 tenants or we say in Modern SharePoint experience by default the custom scripting is not allowed  on the tenant. If custom script is not allowed on your tenant some features will not work  o n your tenants. In common terms you may not able to  save site as template , options to create web part page will not appear on, some web parts  ( like media and content editor) will also not there.   How to