3

I have following .ascx file

<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Control Language="C#" AutoEventWireup="false" %>
<SharePoint:RenderingTemplate runat="server" ID="CustomListForm">
  <Template>
    <asp:Label runat="server" Text="This is the CustomListForm template." />
  </Template>
</SharePoint:RenderingTemplate>

The custom template is used when displaying an item in the following internal list instance

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <ListInstance Title="InternalListInstance"
                OnQuickLaunch="TRUE"
                TemplateType="100"
                FeatureId="00bfea71-de22-43b2-a848-c05709900100"
                Url="Lists/InternalListInstance"
                CustomSchema="InternalListInstance\Schema.xml"
                Description="Internal List">
  </ListInstance>
</Elements>

with schema defined as

<?xml version="1.0" encoding="utf-8" ?>
<List Title="InternalListInstance" Direction="none" Url="Lists/InternalListInstance" BaseType="0" Type="100" FolderCreation="FALSE" DisableAttachments="TRUE" xmlns:ows="Microsoft SharePoint" xmlns="http://schemas.microsoft.com/sharepoint/">
  <MetaData>
    <ContentTypes>
      <ContentType ID="0x01" Name="Item" Group="List Content Types" Description="Create a new list item." FeatureId="{695b6570-a48b-4a8e-8ea5-26ea7fc1d162}">
        <Folder TargetName="Item" />
        <FieldRefs>
          <FieldRef ID="{c042a256-787d-4a6f-8a8a-cf6ab767f12d}" Name="ContentType" />
          <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" Required="TRUE" ShowInNewForm="TRUE" ShowInEditForm="TRUE" />
        </FieldRefs>
        <XmlDocuments>
          <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
            <FormTemplates xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
              <Display>CustomListForm</Display>
              <Edit>ListForm</Edit>
              <New>ListForm</New>
            </FormTemplates>
          </XmlDocument>
        </XmlDocuments>
      </ContentType>
    </ContentTypes>
    <Fields>
    </Fields>
    <Forms>
      <Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx" Template="CustomListForm" WebPartZoneID="Main" />
      <Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx" Template="ListForm" WebPartZoneID="Main" />
      <Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" Template="ListForm" WebPartZoneID="Main" />
    </Forms>
    <Views>
      <View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="All Items" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="AllItems.aspx">
        <Toolbar Type="Standard" />
        <XslLink>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>
      </View>
    </Views>
  </MetaData>
</List>

The custom form template is not used when displaying an item in the following external list instance

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <ListInstance Title="ExternalListInstance"
                OnQuickLaunch="TRUE"
                TemplateType="600"
                Url="Lists/ExternalListInstance"
                CustomSchema="ExternalListInstance\Schema.xml"
                Description="External List">
    <DataSource>
      <Property Name="LobSystemInstance" Value="MyLobSystem" />
      <Property Name="EntityNamespace" Value="MyNamespace" />
      <Property Name="Entity" Value="Coworker" />
      <Property Name="SpecificFinder" Value="ReadItem" />
    </DataSource>
  </ListInstance>
</Elements>

with schema defined as

<?xml version="1.0" encoding="utf-8" ?>
<List Title="ExternalListInstance" Direction="none" Url="Lists/ExternalListInstance" BaseType="0" Type="600" FolderCreation="FALSE" DisableAttachments="TRUE" xmlns:ows="Microsoft SharePoint" xmlns="http://schemas.microsoft.com/sharepoint/">
  <MetaData>
    <ContentTypes>
      <ContentType ID="0x01" Name="Item" Group="List Content Types" Description="Create a new list item." FeatureId="{695b6570-a48b-4a8e-8ea5-26ea7fc1d162}">
        <Folder TargetName="Item" />
        <FieldRefs>
          <FieldRef ID="{c042a256-787d-4a6f-8a8a-cf6ab767f12d}" Name="ContentType" />
          <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" Required="TRUE" ShowInNewForm="TRUE" ShowInEditForm="TRUE" />
        </FieldRefs>
        <XmlDocuments>
          <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
            <FormTemplates xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
              <Display>CustomListForm</Display>
              <Edit>ListForm</Edit>
              <New>ListForm</New>
            </FormTemplates>
          </XmlDocument>
        </XmlDocuments>
      </ContentType>
    </ContentTypes>
    <Fields>
      <Field DisplayName="BDC Identity" Hidden="FALSE" Name="BdcIdentity" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="BdcIdentity" Type="Text" />
      <Field DisplayName="Coworker ID" Hidden="FALSE" Name="CoworkerId" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="CoworkerId" Type="Integer" />
      <Field DisplayName="First Name" Hidden="FALSE" Name="FirstName" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="FirstName" Type="Text" />
      <Field DisplayName="Last Name" Hidden="FALSE" Name="LastName" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="LastName" Type="Text" />
      <Field DisplayName="Email" Hidden="FALSE" Name="Email" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="Email" Type="Text" />
      <Field DisplayName="Account" Hidden="FALSE" Name="SamAccountName" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="SamAccountName" Type="Text" />
      <Field DisplayName="Personnel Number" Hidden="FALSE" Name="PersonnelNumber" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="PersonnelNumber" Type="Text" />
      <Field DisplayName="Birthday" Hidden="FALSE" Name="Birthday" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="Birthday" Type="DateTime" />
    </Fields>
    <Forms>
      <Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx" Template="CustomListForm" WebPartZoneID="Main" />
      <Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx" Template="ListForm" WebPartZoneID="Main" />
      <Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" Template="ListForm" WebPartZoneID="Main" />
    </Forms>
    <Views>
      <View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="Read List" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="ReadList.aspx">
        <Toolbar Type="Standard" />
        <Method Name="ReadList" />
        <XslLink>main.xsl</XslLink>
        <RowLimit Paged="TRUE">30</RowLimit>
        <ViewFields>
          <FieldRef Name="CoworkerId" />
          <FieldRef Name="FirstName" />
          <FieldRef Name="LastName" />
          <FieldRef Name="Email" />
          <FieldRef Name="SamAccountName" />
        </ViewFields>
        <Query>
          <OrderBy>
            <FieldRef Name="CoworkerId"></FieldRef>
          </OrderBy>
        </Query>
      </View>
    </Views>
  </MetaData>
</List>

At no time SharePoint 2010 accepts the declarations for the custom form templates. The form template $l.Forms[0].TemplateName and the content type form template $l.ContentTypes[0].DisplayFormTemplateName is set to ListForm. Trying to change the content type's template throws following error

$l.ContentTypes[0].DisplayFormTemplateName = "CustomListForm"
$l.ContentTypes[0].Update()
Exception calling "Update" with "0" argument(s): "The collection cannot be modified."
At line:1 char:26
+ $l.ContentTypes[0].Update <<<< ()
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

I have the feeling that custom form templates do not work with external lists. Am I right?

1 Answer 1

0

In your Schema.xml, you're assosciating the CustomListForm with the Item content type, not your BCS entity.

I think what you want to do here is, inside the <Forms> tag for the List Definition, insert the link to your custom form and put UseLegacyForms to true.

1
  • Schema.xml with and without contentype definition combined with UseLegacyForm="TRUE" has no effect. The standard ListForm template is going to be used. If you create an external list through the SharePoint GUI that list has always an content type Item associated. Checked it with PowerShell and SharePoint Manager. I have associated my list with the BCS entity. Look DataSource element in the ListInstance.
    – Yavuz
    Commented Feb 12, 2013 at 10:46

Your Answer

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

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