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".

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

  • Able to create ContentType but it is not creating the "EmailId" and "Name" fields. – Dilip Kumar Yadav Aug 10 '17 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. – Gautam Sheth Aug 10 '17 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. – Gautam Sheth Aug 10 '17 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. – Dilip Kumar Yadav Aug 11 '17 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. – Gautam Sheth Aug 11 '17 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.