AddContentTypeField - cannot add field to Content Type
-
29-09-2020 - |
Question
I have a list with content type in it. I'm trying to add a field to this content type so I can use it in the library. Here's I've added Elements.1.0.0.1.xml file to Content Type:
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Field ID="{63F353F8-F206-4BB0-A3C1-1B8FA9E43C63}" DisplayName="Dull field" Name="DULLfield" Type="Text" Group="RM" Overwrite="TRUE" />
</Elements>
Then I've added Upgrade Action to Feature.Template.xml:
<UpgradeActions>
<VersionRange BeginVersion="0.0.0.0" EndVersion="10.0.0.0">
<ApplyElementManifests>
<ElementManifest Location="MyContentType\Elements.1.0.0.1.xml"/>
</ApplyElementManifests>
<AddContentTypeField ContentTypeId="0x0120D520005C2CAF72F4414435A29E0ACDC59F28D9" FieldId="{63F353F8-F206-4BB0-A3C1-1B8FA9E43C63}" PushDown="TRUE"/>
</VersionRange>
</UpgradeActions>
Then I run following script with no errors or warnings:
Update-SPSolution -Identity sharepointproject1.wsp -LiteralPath "C:\SharePointProject1.wsp" -GA
CDeployment
Now I can see new field in Site Columns, but not in my Content Type. I suppose PushDown="TRUE"
parameter has to add new field to a content type, but it doesn't. What do I miss?
======== Update ======== Deployed solution with Version = 1.0.0.0, then changed Version to 2.0.0.0, Publish WSP file to local disk, run Update-SPSolution. When I get Solution version via PowerShell
$f = Get-SPFeature | where{$_.DisplayName -eq '
myfeature'}
$f.version
It's still 1.0.0.0. I've opened wsp feature.xml file inside wsp file - it has correct version 2.0.0.0
What do I miss?
Solution 2
I've finally got the upgrade done. Here's a list of actions I proceeded:
1.Update spsolution (.wsp file):
Update-SPSolution -Identity SharePointProject58.wsp -LiteralPath "<Path>" -GACDeployment
2.Upgrade feature:
$feature = $web.Features | where{$_.Definition.DisplayName -eq '*myfeature*'}
$feature.Upgrade($true)
And the most important part: You have to restart console after every time you update solution, otherwise it sticks to old version! Here's good article on the subject.
OTHER TIPS
Give versioning to the feature, i.e. VersionRange id, then remove from VersionRange the BeginVersion property.
Exemple:
<Feature xmlns="http://schemas.microsoft.com/sharepoint/" Version="10.0.0.0">
<UpgradeActions>
<VersionRange EndVersion ="10.0.0.0">
<ApplyElementManifests>
<ElementManifest Location="MyContentType\Elements.1.0.0.1.xml"/>
</ApplyElementManifests>
<AddContentTypeField ContentTypeId="0x0120D520005C2CAF72F4414435A29E0ACDC59F28D9" FieldId="{63F353F8-F206-4BB0-A3C1-1B8FA9E43C63}" PushDown="TRUE"/>
</VersionRange>
</UpgradeActions>
</Feature>
Hope it helps.