Pnpframework: Adding existing content types to library deletes them in 1.3.0

Created on 12 Feb 2021  Â·  6Comments  Â·  Source: pnp/pnpframework

I am adding extra content types defined on the Site level to the "Documents" library via a provisioning template (first, third and fourth line in pnp:ContentTypeBindings):

      <pnp:Lists>
        <pnp:ListInstance Title="Dokumenty" Description="" DocumentTemplate="{site}/Sdilene dokumenty/Forms/template.dotx" OnQuickLaunch="true" TemplateType="101" Url="Sdilene dokumenty" EnableVersioning="true" MinorVersionLimit="0" MaxVersionLimit="500" DraftVersionVisibility="0" TemplateFeatureID="00bfea71-e717-4e80-aa17-d0c71b360101" ContentTypesEnabled="true" EnableAttachments="false" DefaultDisplayFormUrl="{site}/Sdilene dokumenty/Forms/DispForm.aspx" DefaultEditFormUrl="{site}/Sdilene dokumenty/Forms/EditForm.aspx" DefaultNewFormUrl="{site}/Sdilene dokumenty/Forms/Upload.aspx" ImageUrl="/_layouts/15/images/itdl.png?rev=47" IrmExpire="false" IrmReject="false" IsApplicationList="false" ReadSecurity="0" WriteSecurity="0" ValidationFormula="" ValidationMessage="" EnableFolderCreation="false" >
          <pnp:ContentTypeBindings>
            <pnp:ContentTypeBinding ContentTypeID="0x010100BF87545EA10ECE43B34F659BC08D9129" Default="true"/>
            <pnp:ContentTypeBinding ContentTypeID="0x0120"/>
            <pnp:ContentTypeBinding ContentTypeID="0x0120D52000E31C3CDFB447B943AA017C95EE1660BA"/>
            <pnp:ContentTypeBinding ContentTypeID="0x0101008D022B8BE33B8242BD95268C8C48D66C"/>
            <pnp:ContentTypeBinding ContentTypeID="0x0101" Remove="true"/>
            <pnp:ContentTypeBinding ContentTypeID="0x0120D520" Remove="true"/>            
          </pnp:ContentTypeBindings>

image

In PnP.PowerShell 1.2.0 it worked as expected, but after installing 1.3.0 version, it suddenly started to delete the content types from the library.

provisioning âš™ bug

All 6 comments

I'm experiencing a problem that may be related and also appeared after I upgraded the PnP.PowerShell module to the 1.3.0 version (previous version was 1.2.6-nightly).
I apply three content types published from the content type hub to the library of a new site (once content types have been published) :

          <pnp:ContentTypeBindings>
            <pnp:ContentTypeBinding ContentTypeID="0x01010032E4B8FFFFCF9B4BA24E6C4A697F518D" Default="true" />
            <pnp:ContentTypeBinding ContentTypeID="0x0120" />
            <pnp:ContentTypeBinding ContentTypeID="0x01010032E4B8FFFFCF9B4BA24E6C4A697F518D01" />
            <pnp:ContentTypeBinding ContentTypeID="0x01010032E4B8FFFFCF9B4BA24E6C4A697F518D02" />
            <pnp:ContentTypeBinding ContentTypeID="0x0101" Remove="true" />
          </pnp:ContentTypeBindings>

and with this new version it ends up with an error message stating that the first content type (0x01010032E4B8FFFFCF9B4BA24E6C4A697F518D) is read only which is normal for a CTH published content type.

I reverted to my previous version and template is applied with no problem.

@adzero / @makovickanavisys : can you prep a repro template, will make it easier for us to repro/fix this one

@jansenbe , here's a simplified template that triggers the error I encounter.

<?xml version="1.0"?>
<pnp:Provisioning xmlns:pnp="http://schemas.dev.office.com/PnP/2020/02/ProvisioningSchema">
  <pnp:Templates ID="TEMPLATES">
    <pnp:ProvisioningTemplate ID="TEST-TEMPLATE" Version="1" BaseSiteTemplate="STS#3" Scope="RootSite">
      <pnp:SiteSettings AllowDesigner="true" AllowCreateDeclarativeWorkflow="false" AllowSaveDeclarativeWorkflowAsTemplate="false" AllowSavePublishDeclarativeWorkflow="false" SearchBoxInNavBar="Inherit" />
      <pnp:WebSettings Title="Test" Description="Test" RequestAccessEmail="" DisableFlows="true" DisableAppViews="true" NoCrawl="false" WelcomePage="SitePages/Home.aspx" SiteLogo="" AlternateCSS="" MasterPageUrl="{masterpagecatalog}/seattle.master" CustomMasterPageUrl="{masterpagecatalog}/seattle.master" CommentsOnSitePagesDisabled="true" QuickLaunchEnabled="true" MembersCanShare="false" SearchScope="DefaultScope" SearchBoxInNavBar="Inherit" />
      <pnp:RegionalSettings AdjustHijriDays="0" AlternateCalendarType="None" CalendarType="Gregorian" Collation="12" FirstDayOfWeek="Monday" FirstWeekOfYear="0" LocaleId="1036" ShowWeeks="false" Time24="true" TimeZone="4" WorkDayEndHour="6:00PM" WorkDays="62" WorkDayStartHour="8:00AM" />
      <pnp:Lists>
        <pnp:ListInstance Title="Documents" Description="" DocumentTemplate="{site}/Documents partages/Forms/template.dotx" OnQuickLaunch="true" TemplateType="101" Url="Documents partages" EnableVersioning="true" MinorVersionLimit="0" MaxVersionLimit="100" DraftVersionVisibility="0" TemplateFeatureID="00bfea71-e717-4e80-aa17-d0c71b360101" ContentTypesEnabled="true" EnableAttachments="false" EnableFolderCreation="false" DefaultDisplayFormUrl="{site}/Documents partages/Forms/DispForm.aspx" DefaultEditFormUrl="{site}/Documents partages/Forms/EditForm.aspx" DefaultNewFormUrl="{site}/Documents partages/Forms/Upload.aspx" ImageUrl="/_layouts/15/images/itdl.png?rev=47" IrmExpire="false" IrmReject="false" IsApplicationList="false" ValidationFormula="" ValidationMessage="">
          <pnp:PropertyBagEntries>
            <pnp:PropertyBagEntry Key="IsAttachmentLibrary" Value="0" Overwrite="false" />
          </pnp:PropertyBagEntries>
          <pnp:ContentTypeBindings>
            <pnp:ContentTypeBinding ContentTypeID="0x01010032E4B8FFFFCF9B4BA24E6C4A697F518D" Default="true" />
            <pnp:ContentTypeBinding ContentTypeID="0x0101" Remove="true" />
          </pnp:ContentTypeBindings>
          <pnp:Views>
            <View Name="{DA89F95C-9D7D-40CA-9C98-55E4D18F2245}" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" Type="HTML" DisplayName="Tous les documents" Url="{site}/Documents partages/Forms/AllItems.aspx" Level="1" BaseViewID="1" ContentTypeID="0x" ImageUrl="/_layouts/15/images/dlicon.png?rev=47">
              <Query>
                <OrderBy>
                  <FieldRef Name="FileLeafRef" />
                </OrderBy>
              </Query>
              <ViewFields>
                <FieldRef Name="DocIcon" />
                <FieldRef Name="LinkFilename" />
                <FieldRef Name="Modified" />
                <FieldRef Name="Editor" />
              </ViewFields>
              <RowLimit Paged="TRUE">30</RowLimit>
              <JSLink>clienttemplates.js</JSLink>
              <SpotlightInfo>|0=8|</SpotlightInfo>
            </View>
          </pnp:Views>
        </pnp:ListInstance>
      </pnp:Lists>
      <pnp:Header Layout="Standard" />
    </pnp:ProvisioningTemplate>
  </pnp:Templates>
</pnp:Provisioning>

As explained before, the content type binding in the Documents library corresponds to a content type published with a content type hub. The Id in the template should be replaced with an existing one :

<pnp:ContentTypeBinding ContentTypeID="0x01010032E4B8FFFFCF9B4BA24E6C4A697F518D" Default="true" />

Attaching simplified template for Shared Documents - it creates a test site content type and then tries to attach the content type to the Shared Documents library (and delete default Document content type):

<?xml version="1.0"?>
<pnp:Provisioning xmlns:pnp="http://schemas.dev.office.com/PnP/2020/02/ProvisioningSchema">
  <pnp:Preferences Generator="PnP.Framework, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null" />
  <pnp:Templates ID="CONTAINER-TEMPLATE-F58EE98711994592B93E425E2328DF33">
    <pnp:ProvisioningTemplate ID="TEMPLATE-F58EE98711994592B93E425E2328DF33" Version="1" BaseSiteTemplate="STS#3" Scope="RootSite">

      <pnp:ContentTypes>
        <pnp:ContentType ID="0x01010068C42A1C3BC050409A16B485D2F08CEB" Name="TestContentType" Description="Create a new document." Group="Custom Content Types" NewFormUrl="" EditFormUrl="" DisplayFormUrl="">
          <pnp:FieldRefs>
            <pnp:FieldRef ID="c042a256-787d-4a6f-8a8a-cf6ab767f12d" Name="ContentType" UpdateChildren="true" />
            <pnp:FieldRef ID="5f47e085-2150-41dc-b661-442f3027f552" Name="SelectFilename" UpdateChildren="true" />
            <pnp:FieldRef ID="8553196d-ec8d-4564-9861-3dbe931050c8" Name="FileLeafRef" Required="true" UpdateChildren="true" />
            <pnp:FieldRef ID="8c06beca-0777-48f7-91c7-6da68bc07b69" Name="Created" Hidden="true" UpdateChildren="true" />
            <pnp:FieldRef ID="fa564e0f-0c70-4ab9-b863-0177e6ddd247" Name="Title" UpdateChildren="true" />
            <pnp:FieldRef ID="28cf69c5-fa48-462a-b5cd-27b6f9d2bd5f" Name="Modified" Hidden="true" UpdateChildren="true" />
            <pnp:FieldRef ID="822c78e3-1ea9-4943-b449-57863ad33ca9" Name="Modified_x0020_By" UpdateChildren="true" />
            <pnp:FieldRef ID="4dd7e525-8d6b-4cb4-9d3e-44ee25f973eb" Name="Created_x0020_By" UpdateChildren="true" />
          </pnp:FieldRefs>
        </pnp:ContentType>
      </pnp:ContentTypes>

      <pnp:Lists>
        <pnp:ListInstance Title="Documents" Description="" DocumentTemplate="{site}/Shared Documents/Forms/template.dotx" OnQuickLaunch="true" TemplateType="101" Url="Shared Documents" EnableVersioning="true" MinorVersionLimit="0" MaxVersionLimit="500" DraftVersionVisibility="0" TemplateFeatureID="00bfea71-e717-4e80-aa17-d0c71b360101" ContentTypesEnabled="true" EnableAttachments="false" DefaultDisplayFormUrl="{site}/Shared Documents/Forms/DispForm.aspx" DefaultEditFormUrl="{site}/Shared Documents/Forms/EditForm.aspx" DefaultNewFormUrl="{site}/Shared Documents/Forms/Upload.aspx" ImageUrl="/_layouts/15/images/itdl.png?rev=47" IrmExpire="false" IrmReject="false" IsApplicationList="false" ValidationFormula="" ValidationMessage="">
          <pnp:ContentTypeBindings>
            <pnp:ContentTypeBinding ContentTypeID="0x0101" Remove="true"/>
            <pnp:ContentTypeBinding ContentTypeID="0x0120" />
            <pnp:ContentTypeBinding ContentTypeID="0x01010068C42A1C3BC050409A16B485D2F08CEB" Default="true" />
          </pnp:ContentTypeBindings>
          <pnp:Views>
            <View Name="{5E1AA7E5-1152-4E28-B490-4AC1F75355FA}" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" Type="HTML" DisplayName="All Documents" Url="{site}/Shared Documents/Forms/AllItems.aspx" Level="1" BaseViewID="1" ContentTypeID="0x" ImageUrl="/_layouts/15/images/dlicon.png?rev=47">
              <Query>
                <OrderBy>
                  <FieldRef Name="FileLeafRef" />
                </OrderBy>
              </Query>
              <ViewFields>
                <FieldRef Name="DocIcon" />
                <FieldRef Name="LinkFilename" />
                <FieldRef Name="Modified" />
                <FieldRef Name="Editor" />
              </ViewFields>
              <RowLimit Paged="TRUE">30</RowLimit>
              <JSLink>clienttemplates.js</JSLink>
            </View>
          </pnp:Views>
        </pnp:ListInstance>
      </pnp:Lists>
    </pnp:ProvisioningTemplate>
  </pnp:Templates>
</pnp:Provisioning>

On 1.2.0 it works, on 1.3.0 it tries to delete the "TestContentType" from the library.

@adzero / @makovickanavisys : I've managed to repro and fix things (see https://github.com/pnp/pnpframework/commit/e7cc2c39a3cc9e4c398dcdad58a8b67082b483d4). Please verify with our nightly releases (PnP PowerShell / PnP Framework) tomorrow and let me know if things also work for you.

Tested on 1.3.7 and it worked correctly.

Was this page helpful?
0 / 5 - 0 ratings