1

I am able to create a custom list in spfx webpart through elements.xml with the following xml snippet:

<?xml version="1.0" encoding="utf-8"?>  
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">  
    <ListInstance   
            FeatureId="00bfea71-de22-43b2-a848-c05709900100"  
            Title="TestSPFxList3"   
            Description="New SP List"  
            TemplateType="100"  
            Url="Lists/TestSPFxList3">  
    </ListInstance>  
</Elements> 

How do I add columns to it.? Let's say column "Name" and "EmailId".

1 Answer 1

4

You need to wrap it inside the <Field> tag as below in the element.xml file.

<Field ID="{060E50AC-E9C1-4D3C-B1F9-DE0BCAC300F6}"
            Name="EmailId"
            DisplayName="Email Id"
            Type="Text"
            Description ="Some desc"
            Required="TRUE"
            MaxLength="50"
            Group="SPFx Columns"></Field>

So, your full XML would be somewhat as below:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

    <Field ID="{060E50AC-E9C1-4D3C-B1F9-DE0BCAC300F6}"
            Name="EmailId"
            DisplayName="Email Id"
            Type="Text"
            Description ="Some desc."
            Required="TRUE"
            MaxLength="50"
            Group="SPFx Columns" >

    <Field ID="{943E7530-5E2B-4C02-8259-CCD93A9ECB18}"
            Name="CustomChoice"
            DisplayName="Choice Field"
            Type="Choice"
            Required="FALSE"
            Group="SPFx Columns">
        <CHOICES>
        <CHOICE>Blue</CHOICE>
        <CHOICE>Green</CHOICE>
        <CHOICE>Green</CHOICE>        
        </CHOICES>
    </Field>

    <ContentType ID="0x010042D0C1C200A14B6887742B6344675C8B" 
            Name="My Content Type" 
            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}" />
        </FieldRefs>
    </ContentType> 

    <ListInstance   
            FeatureId="00bfea71-de22-43b2-a848-c05709900100"  
            Title="TestSPFxList3"   
            Description="New SP List"  
            TemplateType="100"  
            Url="Lists/TestSPFxList3">  
    </ListInstance> 
</Elements>

Reference- Provision SP assets from package

6
  • Able to create ContentType but it is not creating the "EmailId" and "Name" fields. Commented Aug 10, 2017 at 9:28
  • Any errors ? You cant use Name as internal name, its a default field, replace it with something like CustomName. Also, try to create a new package and check. Commented Aug 10, 2017 at 9:38
  • Also, i think you need to attach that content type to the list, once you do that the field will be visible. Commented Aug 10, 2017 at 10:44
  • I followed this article: dev.office.com/sharepoint/docs/spfx/web-parts/get-started/… I was missing the schema.XML file and operations performed in it. Not I am able to create the columns. Commented Aug 11, 2017 at 13:22
  • 1
    Just use a single element.xml and multiple schema.xml. So, for example, to create 2 lists, create list instances in the element.xml file and separate the schemas via schema.xml , schema2.xml like that. Commented Aug 11, 2017 at 13:36

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.