Skip to content

List FieldRef (Ref to Site Column) won't be exported if this list enabled content type management and this field is not visible on list content types #1230

@wuxiaojun514

Description

@wuxiaojun514

I found an interesting problem when run Export-PnPListToSiteTemplate command.

My Scenario

Let me describe my scenario first.

I have one list which enabled content type management, because I have two content types under this list

Image

Some of the list fields are site column

Image

And these two site columns are set as hidden in my list content type

Image

Missing site column field ref in the exported template

Then it (those two site column field ref) won't get exported when I run Export-PnPListToSiteTemplate or other export template command.
In this case it only exported "Title" since "Tifle" field is visible in list content type
Image

However if I disable the content type management on the list, then I can get all site columns used in this list.

Image

In the source code https://github.com/pnp/pnpframework/blob/dev/src/lib/PnP.Framework/Provisioning/ObjectHandlers/ObjectListInstance.cs#L2776, it will not add hidden site column as field ref if the list enabled content type

  if (siteList.ContentTypesEnabled && contentTypeFields.FirstOrDefault(c => c.Id == field.Id) == null)
                    {
                        if (contentTypeFields.FirstOrDefault(c => c.Id == field.Id) == null)
                        {
                            addField = false;
                        }
                    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions