powershell icon indicating copy to clipboard operation
powershell copied to clipboard

[BUG] Issue with exporting PnP Field default values

Open AndersRask opened this issue 3 years ago • 0 comments

Reporting an Issue or Missing Feature

FieldDefault values not included in Site Template export for text fields associated with Content Type, using Get-PnPSiteTemplate

Expected behavior

When defining a default value on a list with enabled content types, I noticed that default values specified on the list does not get exported into pnp:FieldDefault entries for text fields (it worked with term columns but haven't tested other fields so far)

Actual behavior

The field that you have changed default value for are included in pnp:FieldRefs, but the entry in pnp:FieldDefaults is missing

Steps to reproduce behavior

Create Site Content type that inherits from Document and add a text field ("test1") and a taxonomy field ("test2") Create a new Document Library, enable content types, add the content type to the list To prove that default values for text fields work, you may also add a text field ("test3") on the library and add an existing site column that is not associated to the content type ("test4") Go to Change Default Column Values on library and set default values for the added fields

call Get-PnPSiteTemplate and output to template.xml

When you examine template.xml you will notice that pnp:FieldDefaults contains the non-CT associated field and the taxonomy default, but not the CT associated text field. In pnp:Field the default for the field is also included:


<pnp:Fields>
                        <Field Type="Text" DisplayName="test3" Required="FALSE" EnforceUniqueValues="FALSE" Indexed="FALSE" MaxLength="255" ID="{a02448c9-2edb-4fdb-b8b6-b2303e59b330}" SourceID="{{listid:Documents}}" StaticName="test3" Name="test3" ColName="nvarchar17" RowOrdinal="0">
                            <Default>test3</Default>
                        </Field>
</pnp:Fields>
<pnp:FieldRefs>
                        <pnp:FieldRef ID="1b64e20a-952d-4ed4-a357-5c962ef16052" Name="test1" DisplayName="test1" />
                        <pnp:FieldRef ID="9879f367-3712-4d94-a24b-8a7da7daaf11" Name="test2" DisplayName="test2" />
                        <pnp:FieldRef ID="fa33e131-e798-45df-a438-cebda2168160" Name="test3" DisplayName="test3" />
</pnp:FieldRefs>
<pnp:FieldDefaults>
                        <pnp:FieldDefault FieldName="test2">1;#TEST2|edbb80ed-e9a5-4a2b-ad5c-6d9f6e5e3a82</pnp:FieldDefault>
                        <pnp:FieldDefault FieldName="test4">test4</pnp:FieldDefault>
</pnp:FieldDefaults>

If i manually add test1 to pnp:FieldDefaults and provision a site, it works fine, so I guess it is just a bug in the export?

What is the version of the Cmdlet module you are running?

1.9.17

Which operating system/environment are you running PnP PowerShell on?

  • [x] Windows
  • [ ] Linux
  • [ ] MacOS
  • [ ] Azure Cloud Shell
  • [ ] Azure Functions
  • [ ] Other : please specify

AndersRask avatar Jan 20 '22 13:01 AndersRask