10

I am trying to use the SharePoint Framework to provision a list with some default data, I managed to get this working using the following elements.xml and custom schema.xml. This worked no problem creating a SharePoint Add-Inn but was more difficult using the spfx, after much trial and error things are working good. Hopefully this will help someone else who is trying to get this working.

Elements.xml:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<Field ID="{060E50AC-E9C1-4D3C-B1F9-DE0BCAC300F6}"
        Name="SPFxFileType"
        DisplayName="File Type"
        Type="Text"
        Required="FALSE"
        Group="SPFx Columns" />

<Field ID="{943E7530-5E2B-4C02-8259-CCD93A9ECB18}"
        Name="SPFxFileName"
        DisplayName="File Name"
        Type="Text"
        Required="FALSE"
        Group="SPFx Columns">
</Field>
<Field ID="{943E7530-5E2B-4C02-8259-CCD93A9ECB19}"
        Name="SPFxTeam"
        DisplayName="Team"
        Type="Text"
        Required="FALSE"
        Group="SPFx Columns">
</Field>

<ContentType ID="0x010042D0C1C200A14B6887742B6344675C8B" 
        Name="Files List" 
        Group="SPFx Content Types" 
        Description="Sample content types from web part solution">
    <FieldRefs>
        <FieldRef ID="{060E50AC-E9C1-4D3C-B1F9-DE0BCAC300F6}" /> 
        <FieldRef ID="{943E7530-5E2B-4C02-8259-CCD93A9ECB18}" />
        <FieldRef ID="{943E7530-5E2B-4C02-8259-CCD93A9ECB19}" />
    </FieldRefs>
</ContentType> 

<ListInstance 
        CustomSchema="schema.xml"
        FeatureId="00bfea71-de22-43b2-a848-c05709900100"
        Title="SPFxList" 
        Description="SPFx List"
        TemplateType="100"
        Url="Lists/SPFxList">
        <Data>
            <Rows>
                <Row>
                <Field Name="Title">Autoexec</Field>
                <Field Name="SPFxFileName">Autoexec</Field>
                <Field Name="SPFxFileType">bat</Field>
                <Field Name="SPFxTeam">Microsoft</Field>
                </Row>
                <Row>
                <Field Name="Title">Config</Field>
                <Field Name="SPFxFileName">Config</Field>
                <Field Name="SPFxFileType">sys</Field>
                <Field Name="SPFxTeam">EMC</Field>
                </Row>
                <Row>
                <Field Name="Title">Hosts</Field>
                <Field Name="SPFxFileName">Hosts</Field>
                <Field Name="SPFxFileType">exe</Field>
                <Field Name="SPFxTeam">Dell</Field>
                </Row>
                <Row>
                <Field Name="Title">Bootstrap</Field>
                <Field Name="SPFxFileName">Bootstrap</Field>
                <Field Name="SPFxFileType">js</Field>
                <Field Name="SPFxTeam">EMC</Field>
                </Row>
                <Row>
                <Field Name="Title">Startup</Field>
                <Field Name="SPFxFileName">Startup</Field>
                <Field Name="SPFxFileType">css</Field>
                <Field Name="SPFxTeam">Dell</Field>
                </Row>
            </Rows>
        </Data>
</ListInstance>

</Elements>

Schema.xml:

<List xmlns:ows="Microsoft SharePoint" Title="Basic List" EnableContentTypes="TRUE" FolderCreation="FALSE"  Direction="$Resources:Direction;" Url="Lists/Basic 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="/_layouhttps://devofficecdn.azureedge.net/sharepointdocumentation/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="SPFxFileName"></FieldRef>
      <FieldRef Name="SPFxFileType"></FieldRef>
      <FieldRef Name="SPFxTeam"></FieldRef>
    </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>

package-solution.json:

 {
 "solution": {
 "name": "asset-deployment-webpart-client-side-solution",
 "id": "31086065-dbdb-493f-b02e-7b7f97f45bd9",
 "version": "2.4.0.0",
 "features": [{
  "title": "asset-deployment-webpart-client-side-solution",
  "description": "asset-deployment-webpart-client-side-solution",
  "id": "523fe887-ced5-4036-b564-8dad5c6c6e24",
  "version": "2.4.0.0",
  "assets": {        
    "elementManifests": [
      "elements.xml"
    ],
    "elementFiles":[
      "schema.xml"
    ]
  }
}]
},
"paths": {
"zippedPackage": "solution/asset-deployment-webpart.sppkg"
}
}

This is what the list looks like after being provisioned in SharePoint:

enter image description here

4
  • I need to implement the same with multiple lists.. can you help me on this
    – TARUN
    May 16, 2017 at 6:00
  • @TARUN: You simply write for each list a seperate schema<LISTNAME>.xml and elements<LISTNAME>.xml and reference this fiels in the assets in the following form: "elementManifests": ["elements<LIST1>.xml","elements<LIST2>.xml",], and so on...
    – Oskar
    Apr 6, 2018 at 13:55
  • 3
    I think you should edit your post, make it look as a question, and then add the rest of the post as an answer, to make it look more like a wiki post ;)
    – Alberto S.
    Feb 25, 2019 at 16:37
  • Agree with @Alberto, in the search results this looks like an unanswered question, I hunted around other places before finally reading this out of desperation.
    – willman
    Feb 18, 2020 at 19:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.