How to Provision the Lookup Fields in SharePoint Office 365 using Patterns and Practices PNP

Sathish Nadarajan
Solution Architect
July 16, 2018
Rate this article
[Total: 0    Average: 0/5]

Few months back, we had seen, how to provision the site columns and content types in Office 365 using PNP here. It was a straight forward implementation.

But, in most of the cases, we require Lookup Fields nowadays. Patterns and Practices is capable enough to take that as well.

Usually, the understanding was like, PNP engine will create the Sitecolumns first, so that if it is a straight forward sitecolumns, without any issue, it will get created. But, when a lookup field tried to create, then at that time, the list was not created. Exception will be thrown. But that understanding was totally a wrong perception.

PNP is intelligent enough to create the site columns, which are having no relationship and create the lists, with those site columns, and come back to create the related site columns. It was really interesting. Let me explain further with the help of the below XML.


 <?xml version="1.0"?>
 <pnp:ProvisioningTemplate ID="SI.SOWTracker" Version="1" xmlns:pnp="">
 <Field Name="ClientCode"
 DisplayName="Client Code"
 EnforceUniqueValues ="TRUE"
 ShowInNewForm='TRUE' >
 <Field Name="ClientCodeLookup"
 Group="My Group"
 <pnp:ContentType ID="0x0100F96F997E5680487B9F800DCEC2901F1D" Name="Client" Description="Client Master Content Type" Group="My Group">
 <!--OOB Fields-->
 <pnp:FieldRef ID="c042a256-787d-4a6f-8a8a-cf6ab767f12d" Name="ContentType" />
 <pnp:FieldRef ID="fa564e0f-0c70-4ab9-b863-0177e6ddd247" Name="Title" Hidden="true" />
 <!--Custom Fields-->
 <pnp:FieldRef ID="316281FD-F612-4798-8D96-350EC8E511D8" Name="ClientCode" />
 <!--Clients List-->
 <pnp:ListInstance Title="Clients" 
 Description="Master list of the Clients" 
 <pnp:ContentTypeBinding ContentTypeID="0x0100F96F997E5680487B9F800DCEC2901F1D" Default="true" />
 <pnp:Views RemoveExistingViews="true">
 <View Name="{54C0247A-CFE2-429C-957A-8B2AF031AE66}" 
 <FieldRef Name="ID" />
 <FieldRef Name="ClientCode" />
 <RowLimit Paged="TRUE">30</RowLimit>
 <pnp:FieldRef ID="316281fd-f612-4798-8d96-350ec8e511d8" Name="ClientCode" DisplayName="Client Code" />


On the above XML, the column ClientCode is referred in a content type and a list got created using that content type. The lookup column which refers the client code from the clients list can also be created using the XML itself. PNP is enough intelligent to create the site column Clientcode, then create the Content Type and then create the List. Now, come back to the site columns section again and create the lookup column Clientcode Lookup, so that, the column referred does not break anything.

Happy Coding,

Sathish Nadarajan.

Author Info

Sathish Nadarajan
Solution Architect
Rate this article
[Total: 0    Average: 0/5]
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 13+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business more

Leave a comment