SOLVED

is there a way to bind list column to an content type in PNP Schema?

Brass Contributor

Hello Everyone,

 

I have created a site content type called "test" and I have a list called "clients" at which i have added this content type as default content type. and then I have added all the list column to it. 

 

When I export the template and apply for new site, list columns are not properly bind to that default content type. Because of this we need to manually add them in that content type again. 

 

Note: We don't want to create these columns as site columns as we have different requirement. 

 

I have failed to make this work, can someone help me out to see something like below when we use template? 

1.PNG

 

PNP Schema that I have exported is(not sure how to bind it for each column here): 

 

<pnp:Fields>
            <Field Type="Note" DisplayName="ManagedService_0" ContentTypeID="0x0100D9A13215F07E8147B12EFE0E4F938757" StaticName="hb203cdb4b95456c904d4fac98c48c7f" Name="hb203cdb4b95456c904d4fac98c48c7f" ID="{2eca7d5d-9518-4c40-8274-b6815d41fcdb}" ShowInViewForms="FALSE" Required="FALSE" Hidden="TRUE" CanToggleHidden="TRUE" ColName="ntext3" RowOrdinal="0" />
</Field>
</pnp:Fields>
            <Field Type="Note" DisplayName="Branch_0" StaticName="od3a075fe9fd48b6ac342fa380061499" Name="od3a075fe9fd48b6ac342fa380061499" ID="{7ede2f99-12a8-448b-ae1d-99c3a23cb446}" ShowInViewForms="FALSE" Required="FALSE" Hidden="TRUE" CanToggleHidden="TRUE" ColName="ntext2" RowOrdinal="0"  />
1 Reply
best response confirmed by gadagottiraj (Brass Contributor)
Solution

Hey @gadagottiraj,

 

Not sure if it will help since you told you don't want to create a site column, but I had a similar problem with content type and I was to find create it using provision.

In my case, I needed to add a column to Site Pages. My solution was to create a site column with the 

Field tag inside the pnp:SiteFields tag, then reference it in both the Site Page Content Type and the Site Pages library. Here's a quick example:

 

<pnp:SiteFields>
        <Field Type="Lookup" DisplayName="FieldName" ID="{fieldID}" SourceID="{{siteid}}" .../>
</pnp:SiteFields>
...
      <pnp:ContentTypes>
        <pnp:ContentType ID="xxxx" Name="Site Page" ...>
          <pnp:FieldRefs>
            <pnp:FieldRef ID="fieldID" Name="FieldName" UpdateChildren="false" />
          </pnp:FieldRefs>
          ...
        </pnp:ContentType>
      </pnp:ContentTypes>

 

 
This way, you can create a site column, include it in your custom content type, and insert your content type in your list. Let me know if you need any help.
1 best response

Accepted Solutions
best response confirmed by gadagottiraj (Brass Contributor)
Solution

Hey @gadagottiraj,

 

Not sure if it will help since you told you don't want to create a site column, but I had a similar problem with content type and I was to find create it using provision.

In my case, I needed to add a column to Site Pages. My solution was to create a site column with the 

Field tag inside the pnp:SiteFields tag, then reference it in both the Site Page Content Type and the Site Pages library. Here's a quick example:

 

<pnp:SiteFields>
        <Field Type="Lookup" DisplayName="FieldName" ID="{fieldID}" SourceID="{{siteid}}" .../>
</pnp:SiteFields>
...
      <pnp:ContentTypes>
        <pnp:ContentType ID="xxxx" Name="Site Page" ...>
          <pnp:FieldRefs>
            <pnp:FieldRef ID="fieldID" Name="FieldName" UpdateChildren="false" />
          </pnp:FieldRefs>
          ...
        </pnp:ContentType>
      </pnp:ContentTypes>

 

 
This way, you can create a site column, include it in your custom content type, and insert your content type in your list. Let me know if you need any help.

View solution in original post