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.
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 andschema2.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.
2. Once the schema files are created, We need to mentioned both the files in our elemenst.xml file.
Two schema files 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!!!!
It work for me
ReplyDeleteIt's helpful for me, thank you some much...
ReplyDelete