locked
Problem when creating list using feature. RRS feed

  • Question

  • Good day.

    Im creating list using feature (Elements.xml).

    My schema.xml file for list is below

    <?xml version="1.0" encoding="utf-8"?>
    <List xmlns:ows="Microsoft SharePoint"
          Title="My simple list"
          FolderCreation="FALSE"
          Direction="LTR"
          Url="Lists/My simple list"
          BaseType="0"
          xmlns="http://schemas.microsoft.com/sharepoint/">
      <MetaData>
        <ContentTypes>
          <ContentTypeRef ID="0x01">
            <Folder TargetName="Item" />
          </ContentTypeRef>
          <ContentTypeRef ID="0x0120" />
        </ContentTypes>
        <Fields>
          <Field ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" DisplayName="Title" Type="Text" FromBaseType="TRUE" StaticName="Title" SourceID="http://schemas.microsoft.com/sharepoint/v3" Required="TRUE"/>
        </Fields>
        <Views>
          <View BaseViewID="0" Type="HTML" MobileView="TRUE" TabularView="FALSE">
            <Toolbar Type="Standard" />
            <XslLink Default="TRUE">main.xsl</XslLink>
            <RowLimit Paged="TRUE">30</RowLimit>
            <ViewFields>
              <FieldRef Name="LinkTitleNoMenu"></FieldRef>
            </ViewFields>
            <Query>
              <OrderBy>
                <FieldRef Name="Modified" Ascending="FALSE"></FieldRef>
              </OrderBy>
            </Query>
            <ParameterBindings>
              <ParameterBinding Name="AddNewAnnouncement" Location="Resource(wss,addnewitem)" />
              <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
              <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_ONET_HOME)" />
            </ParameterBindings>
          </View>
          <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">
            <Toolbar Type="Standard" />
            <XslLink Default="TRUE">main.xsl</XslLink>
            <RowLimit Paged="TRUE">30</RowLimit>
            <ViewFields>
              <FieldRef Name="Attachments"></FieldRef>
              <FieldRef Name="LinkTitle"></FieldRef>
            </ViewFields>
            <Query>
              <OrderBy>
                <FieldRef Name="ID"></FieldRef>
              </OrderBy>
            </Query>
            <ParameterBindings>
              <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
              <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />
            </ParameterBindings>
          </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>

    But after creation this list look strange - when i go to any view form i cannot see column headers.

    If i try to add new record to the list i cannot see this record in view forms.

    What is a cause of a problem?


    Best regards, Chernobrivets

    Saturday, April 28, 2012 1:42 PM

Answers

  • Hi Chernobrivec,

    Looking at your schema.xml, it seems that you will have to use <ContentType> instead of <ContentTypeRef>.

    "ContentTypeRef" is used when you have defined your custom content types. In your case, you can use the "ContentType" node to add custom columns to the list.

    Consider a product list (My Product )having different columns namely "Product Code", "Product", "Product Description" & "Quantity". Then the corresponding list definition (i.e., schema.xml) for the list will be as follows:

    <?xml version="1.0" encoding="utf-8"?>
    <List xmlns:ows="Microsoft SharePoint" Title="My Product List" FolderCreation="FALSE" Direction="$Resources:Direction;" Url="Lists/MyProductList" BaseType="0" xmlns="http://schemas.microsoft.com/sharepoint/">
      <MetaData>
        <ContentTypes>
          <ContentType ID="0x01"  Name="Item" Group="List Content Types" Description="Create a new list item." Overwrite="TRUE">
            <Folder TargetName="Item" />
            <FieldRefs>
              <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" Required="TRUE" ShowInNewForm="TRUE" ShowInEditForm="TRUE" />
              <FieldRef ID="{5c928a8e-84a9-4dfd-9bf7-1a6dbdc39584}" Name="Product" Required="TRUE" />
              <FieldRef ID="{e8f97c70-0b08-4d7c-91d3-34df04794da2}" Name="ProductDescription" Required="FALSE" />
              <FieldRef ID="{ed4c66c1-e748-4cd8-aed2-b8cf02b18f6d}" Name="Quantity" Required="FALSE" />
    	    </FieldRefs>
          </ContentType>
          <ContentTypeRef ID="0x0120" />
        </ContentTypes>
        <Fields>
    	<!-- NOTE : Here ootb title field is used for the column "Product Code" -->
    	<Field ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Type="Text" Name="Title" DisplayName="Product Code" Required="TRUE"
    		SourceID="{$ListId:Lists/MyProductList;}" StaticName="Title" FromBaseType="TRUE" />
    	<Field Type="Text" DisplayName="Product" Description="Name of the product" Required="TRUE" EnforceUniqueValues="FALSE"
    		Indexed="FALSE" MaxLength="255" ID="{5c928a8e-84a9-4dfd-9bf7-1a6dbdc39584}"
    		SourceID="{$ListId:Lists/MyProductList;}" StaticName="Product" Name="Product" />
    	<Field Type="Text" DisplayName="Product Description" Description="Description of the product" Required="FALSE" EnforceUniqueValues="FALSE"
    		Indexed="FALSE" MaxLength="255" ID="{e8f97c70-0b08-4d7c-91d3-34df04794da2}"
    		SourceID="{$ListId:Lists/MyProductList;}" StaticName="ProductDescription" Name="ProductDescription" />
    	<Field Type="Text" DisplayName="Quantity" Description="Quantity in stock" Required="FALSE" EnforceUniqueValues="FALSE"
    		Indexed="FALSE" ID="{ed4c66c1-e748-4cd8-aed2-b8cf02b18f6d}"
    		SourceID="{$ListId:Lists/MyProductList;}" StaticName="Quantity" Name="Quantity" />
        </Fields>
        <Views>
          <View BaseViewID="0" Type="HTML" MobileView="TRUE" TabularView="FALSE">
            <Toolbar Type="Standard" />
            <XslLink Default="TRUE">main.xsl</XslLink>
            <RowLimit Paged="TRUE">30</RowLimit>
            <ViewFields>
              <FieldRef Name="LinkTitleNoMenu"></FieldRef>
            </ViewFields>
            <Query>
              <OrderBy>
                <FieldRef Name="Modified" Ascending="FALSE"></FieldRef>
              </OrderBy>
            </Query>
            <ParameterBindings>
              <ParameterBinding Name="AddNewAnnouncement" Location="Resource(wss,addnewitem)" />
              <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
              <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_ONET_HOME)" />
            </ParameterBindings>
          </View>
          <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">
            <Toolbar Type="Standard" />
            <XslLink Default="TRUE">main.xsl</XslLink>
            <RowLimit Paged="TRUE">30</RowLimit>
            <ViewFields>
                <FieldRef Name="Attachments" />
                <FieldRef Name="LinkTitle" />
                <FieldRef Name="Product" />
                <FieldRef Name="ProductDescription" />
                <FieldRef Name="Quantity" />
            </ViewFields>
            <Query>
              <OrderBy>
                <FieldRef Name="ID"></FieldRef>
              </OrderBy>
            </Query>
            <ParameterBindings>
              <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
              <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />
            </ParameterBindings>
          </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>

    After successful deployment of this list definition, you should be able to see/fill all the custom columns in the View/New/Edit forms of your custom product list.

    Hope this helps!

    • Marked as answer by Lhan Han Thursday, May 3, 2012 3:28 AM
    Saturday, April 28, 2012 3:51 PM

All replies

  • Hi Chernobrivec,

    Looking at your schema.xml, it seems that you will have to use <ContentType> instead of <ContentTypeRef>.

    "ContentTypeRef" is used when you have defined your custom content types. In your case, you can use the "ContentType" node to add custom columns to the list.

    Consider a product list (My Product )having different columns namely "Product Code", "Product", "Product Description" & "Quantity". Then the corresponding list definition (i.e., schema.xml) for the list will be as follows:

    <?xml version="1.0" encoding="utf-8"?>
    <List xmlns:ows="Microsoft SharePoint" Title="My Product List" FolderCreation="FALSE" Direction="$Resources:Direction;" Url="Lists/MyProductList" BaseType="0" xmlns="http://schemas.microsoft.com/sharepoint/">
      <MetaData>
        <ContentTypes>
          <ContentType ID="0x01"  Name="Item" Group="List Content Types" Description="Create a new list item." Overwrite="TRUE">
            <Folder TargetName="Item" />
            <FieldRefs>
              <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" Required="TRUE" ShowInNewForm="TRUE" ShowInEditForm="TRUE" />
              <FieldRef ID="{5c928a8e-84a9-4dfd-9bf7-1a6dbdc39584}" Name="Product" Required="TRUE" />
              <FieldRef ID="{e8f97c70-0b08-4d7c-91d3-34df04794da2}" Name="ProductDescription" Required="FALSE" />
              <FieldRef ID="{ed4c66c1-e748-4cd8-aed2-b8cf02b18f6d}" Name="Quantity" Required="FALSE" />
    	    </FieldRefs>
          </ContentType>
          <ContentTypeRef ID="0x0120" />
        </ContentTypes>
        <Fields>
    	<!-- NOTE : Here ootb title field is used for the column "Product Code" -->
    	<Field ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Type="Text" Name="Title" DisplayName="Product Code" Required="TRUE"
    		SourceID="{$ListId:Lists/MyProductList;}" StaticName="Title" FromBaseType="TRUE" />
    	<Field Type="Text" DisplayName="Product" Description="Name of the product" Required="TRUE" EnforceUniqueValues="FALSE"
    		Indexed="FALSE" MaxLength="255" ID="{5c928a8e-84a9-4dfd-9bf7-1a6dbdc39584}"
    		SourceID="{$ListId:Lists/MyProductList;}" StaticName="Product" Name="Product" />
    	<Field Type="Text" DisplayName="Product Description" Description="Description of the product" Required="FALSE" EnforceUniqueValues="FALSE"
    		Indexed="FALSE" MaxLength="255" ID="{e8f97c70-0b08-4d7c-91d3-34df04794da2}"
    		SourceID="{$ListId:Lists/MyProductList;}" StaticName="ProductDescription" Name="ProductDescription" />
    	<Field Type="Text" DisplayName="Quantity" Description="Quantity in stock" Required="FALSE" EnforceUniqueValues="FALSE"
    		Indexed="FALSE" ID="{ed4c66c1-e748-4cd8-aed2-b8cf02b18f6d}"
    		SourceID="{$ListId:Lists/MyProductList;}" StaticName="Quantity" Name="Quantity" />
        </Fields>
        <Views>
          <View BaseViewID="0" Type="HTML" MobileView="TRUE" TabularView="FALSE">
            <Toolbar Type="Standard" />
            <XslLink Default="TRUE">main.xsl</XslLink>
            <RowLimit Paged="TRUE">30</RowLimit>
            <ViewFields>
              <FieldRef Name="LinkTitleNoMenu"></FieldRef>
            </ViewFields>
            <Query>
              <OrderBy>
                <FieldRef Name="Modified" Ascending="FALSE"></FieldRef>
              </OrderBy>
            </Query>
            <ParameterBindings>
              <ParameterBinding Name="AddNewAnnouncement" Location="Resource(wss,addnewitem)" />
              <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
              <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_ONET_HOME)" />
            </ParameterBindings>
          </View>
          <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">
            <Toolbar Type="Standard" />
            <XslLink Default="TRUE">main.xsl</XslLink>
            <RowLimit Paged="TRUE">30</RowLimit>
            <ViewFields>
                <FieldRef Name="Attachments" />
                <FieldRef Name="LinkTitle" />
                <FieldRef Name="Product" />
                <FieldRef Name="ProductDescription" />
                <FieldRef Name="Quantity" />
            </ViewFields>
            <Query>
              <OrderBy>
                <FieldRef Name="ID"></FieldRef>
              </OrderBy>
            </Query>
            <ParameterBindings>
              <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
              <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />
            </ParameterBindings>
          </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>

    After successful deployment of this list definition, you should be able to see/fill all the custom columns in the View/New/Edit forms of your custom product list.

    Hope this helps!

    • Marked as answer by Lhan Han Thursday, May 3, 2012 3:28 AM
    Saturday, April 28, 2012 3:51 PM
  • Good day.

    Sorry for not responding earlier.

    You mean i should overwrite ootb contenttype?

    I cannot just reference this content type?

    If i use your schema.xml it will overwrite standard item content type for all site collection?


    Best regards, Chernobrivets


    Friday, May 4, 2012 11:38 AM
  • I copied your schema.xml file instead of mine but problem stil persists.

    I want to mention that im using Sharepoint 2007.


    Best regards, Chernobrivets

    Friday, May 4, 2012 2:11 PM