Question

So, I have been using feature upgrading for a while, it works pretty well for existing instances, but as far as I know feature upgrade does not happen automatically, you need to trigger the upgrade, that happens automatically via the feature upgrade toolkit in central administration page.

The problem is that I want to add a new field to the site columns and also add that field to an existing content type.

When the previous developers did this ,they used no feature versioning so version was 0.0.0.0.

I incremented to 1.0.0.0, and this will work fine for existing sites.

However if I create a new site, I am pretty sure that the new field wont be created because for new sites the feature will be 1.0.0.0 not 1.0.0.0 so I wont be able to trigger an upgrade.enter image description here

so here is what I have so far.

Elements_1_0_0_0.xml contains this:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Field ID="{A32453DB-4382-4F5C-8E33-8284AB160E47}" Name="Recurrent" DisplayName="$Resources:SPNLMeetings,Field_AgendaPointRecurrent_Name;" Description="$Resources:SPNLMeetings,Field_AgendaPointRecurrent_Description;" Group="$Resources:SPNLMeetings,Field_NationaleLoterijMeetingColumns_Group;" Type="Boolean" StaticName="Recurrent"  Required="FALSE" />
</Elements>

Template.xml contains this:

<Feature xmlns="http://schemas.microsoft.com/sharepoint/"
  ImageUrl="SPNL\spnl_feature.jpeg"
  Title="$Resources:SPNLMeetings,Feature_NLMeetingsContentTypes_Title"
  Description="$Resources:SPNLMeetings,Feature_NLMeetingsContentTypes_Description" Version="1.0.0.0">
  <UpgradeActions>    
    <VersionRange BeginVersion="0.0.0.0" EndVersion="0.9.9.9">
      <ApplyElementManifests>
        <ElementManifest Location="Fields\Elements_1_0_0_0.xml" />
      </ApplyElementManifests>
      <AddContentTypeField ContentTypeId="0x0120D52000D56C75F51E1BD54E9D59BBBA1925379A01"
          FieldId="{A32453DB-4382-4F5C-8E33-8284AB160E47}" PushDown="TRUE"/>
      <CustomUpgradeAction Name="ReorderFields"/>
    </VersionRange>
  </UpgradeActions>
</Feature>

Preview of feature manifest would look like this:

<Feature xmlns="http://schemas.microsoft.com/sharepoint/" ImageUrl="SPNL\spnl_feature.jpeg" Title="$Resources:SPNLMeetings,Feature_NLMeetingsContentTypes_Title" Description="$Resources:SPNLMeetings,Feature_NLMeetingsContentTypes_Description" Version="1.0.0.0" DefaultResourceFile="SPNLMeetings" Id="5d35f78b-2211-4cd8-bcba-6db7ac456b74" ReceiverAssembly="NationaleLoterij.SharePoint.Meetings.Solution, Version=1.0.0.0, Culture=neutral, PublicKeyToken=212c981019c3ab5d" ReceiverClass="NationaleLoterij.SharePoint.Meetings.Solution.Features.NLMeetingsContentTypes.NLMeetingsContentTypesEventReceiver" Scope="Site">
  <UpgradeActions>
    <VersionRange BeginVersion="0.0.0.0" EndVersion="0.9.9.9">
      <ApplyElementManifests>
        <ElementManifest Location="Fields\Elements_1_0_0_0.xml" />
      </ApplyElementManifests>
      <AddContentTypeField ContentTypeId="0x0120D52000D56C75F51E1BD54E9D59BBBA1925379A01" FieldId="{A32453DB-4382-4F5C-8E33-8284AB160E47}" PushDown="TRUE" />
      <CustomUpgradeAction Name="ReorderFields" />
    </VersionRange>
  </UpgradeActions>
  <ActivationDependencies>
    <ActivationDependency FeatureTitle="$Resources:SPNL,Feature_NLBaseContentTypes_Title" FeatureDescription="$Resources:SPNL,Feature_NLBaseContentTypes_Description" FeatureId="e3356a10-dcd9-45a5-a1f5-6d9695b9c671" />
  </ActivationDependencies>
  <ElementManifests>
    <ElementManifest Location="Fields\Elements.xml" />
    <ElementManifest Location="ContentTypes\Elements.xml" />
    <ElementFile Location="AgendaPointProposedContentTypeResources\docsethomepage.aspx" />
    <ElementManifest Location="AgendaPointProposedContentTypeResources\Elements.xml" />
    <ElementFile Location="AgendaPointContentTypeResources\docsethomepage.aspx" />
    <ElementManifest Location="AgendaPointContentTypeResources\Elements.xml" />
  </ElementManifests>
</Feature>
Was it helpful?

Solution

the answer is here: http://blogs.msdn.com/b/sanjaynarang/archive/2012/02/06/feature-upgrade-adding-fields-to-content-types-and-sharepoint-application-lifecycle-management.aspx

Updating Content Types http://msdn.microsoft.com/en-us/library/aa543504.aspx Do not, under any circumstances, update the content type definition file for a content type after you install and activate that content type. SharePoint Foundation does not track all the changes that are made to the content type definition file. Therefore, you have no reliable method for pushing down all the changes made to site content types to the child content types.

Updating Child Content Types http://msdn.microsoft.com/en-us/library/ms442695.aspx You cannot add columns to an existing site content type declaratively, in other words, by updating the Feature XML files

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top