SOLVED

How to Provision Site Columns and Content Types using Provisioning Template by Patterns and Practice

Copper Contributor

Hi All,

 

I would like to add site columns and content type using PnP provisioning schema xml template. I need XML format for this like sitefields. I am using below xml but it doesnt creating any site column and not giving any error too.

 

<pnp:SiteFields>
      
  
     <Field ID="{793F0419-9A72-48D9-B983-91BD359E5387}" Name="MyCustomPNPField" StaticName="MyCustomPNPField" DisplayName="My Custom PNP Field" Type="Note" Required="FALSE" RichText="FALSE" Group="My Custom PNP Fields" />
      
   </pnp:SiteFields>
12 Replies

how does the rest of your xml look?

<Field Type="Text" DisplayName="Document Number" Required="FALSE" EnforceUniqueValues="FALSE" Indexed="FALSE" MaxLength="255" Group="VO Project" ID="{c2a7fdd0-7a55-40ec-85fc-e5e4de4171d4}" SourceID="{910f1ba0-847d-4238-8de0-fc0cb19047c4}" StaticName="DocumentNumber" Name="DocumentNumber">
</Field>
this is a example of a sitefield
Yes its correct. but i need to add column to list from existing site columns using PnP provisioning schema.With above xml we can add new column to list.Let me corrrect if i am wrong.
best response confirmed by omkar kuchekar (Copper Contributor)
Solution
Yes got the solution. adding existing site column to list as below.

<pnp:FieldRefs>
<pnp:FieldRef ID="baf7091c-01fb-4831-a975-08254f87f234" Name="Non-Working Day" DisplayName="Non-Working Day"></pnp:FieldRef>
</pnp:FieldRefs>
For adding existing content type

<pnp:ContentTypeBindings>
<pnp:ContentTypeBinding ContentTypeID="0x0101" />
</pnp:ContentTypeBindings>

The easiest way to do this is to simply export an existing site after you created the fields and content types manually.

 

Also, if you use Visual Studio you can enable Intellisense. Follow these steps:

 

https://veenstra.me.uk/2015/12/10/office-365sharepoint-2013-enable-intellisense-of-officedevpnp/

But while exporting i am not able to get sitefields,content types so dont know is there any setting or something.I tried adding new site column and exporting but still no sitefields present in XML.

Below link not working.
https://veenstra.me.uk/2015/12/10/office-365sharepoint-2013-enable-intellisense-of-officedevpnp/

You will need to export the root web of the site collection to get all your site fields. Subwebs do not export site fields or site content types. 

ried with root web but still not getting sitefields(site column),content type

Do you mean that you created the fields at the subsite level? That isn't supported and not perticularly following best practise.

 

In short if you created a field Text in subsite 1 and a field Text in subsite 2 then depending on which site was created first the internal names used would become Text and Text1.

 

You might then find that code will fail as unexpected internal names are used. It would be better to create these fields at the top level and reuse the fields across subsite.

Pieter is right. on that one. only rootweb is supported you can do a subsite but it will not retract sitefields and contenttypes!

What if I have subsite site field (lookup). This site field cannot be created on the root web because the list from where it takes data from is on the subsite. 

If I get everything right, this is the real normal case that the tool doesn't support. 

So I cannot use the tool to generate xml and apply it.  

Then it would be a column in the list itself 

1 best response

Accepted Solutions
best response confirmed by omkar kuchekar (Copper Contributor)
Solution
Yes got the solution. adding existing site column to list as below.

<pnp:FieldRefs>
<pnp:FieldRef ID="baf7091c-01fb-4831-a975-08254f87f234" Name="Non-Working Day" DisplayName="Non-Working Day"></pnp:FieldRef>
</pnp:FieldRefs>

View solution in original post