liveBook · Manning

Lookup field

As explained in Practical Automation with PowerShell: Effective scripting from the console to the cloud

A lookup value is a SharePoint field value that references an item in another list.

A lookup field stores a reference to an item in another SharePoint list. It is useful when a request list needs users to choose from centrally maintained options rather than type free-form values. In a site-request workflow, a Template lookup points from Site Requests to the Site Templates list, letting the form present available templates as a drop-down. section 11.2.2

Creating a lookup field with PowerShell requires field XML. The XML identifies the target list through its GUID in List, selects the displayed target column with ShowField, and identifies the destination list through SourceID. Add-PnPFieldFromXml then adds the field to the request list. Making the field required ensures a submitted request includes a template selection. section 11.2.2

$xml = @"
<Field 
    Type="Lookup" 
    DisplayName="Template" 
    Required="TRUE" 
    EnforceUniqueValues="FALSE" 
    List="{$($templateList.Id)}" 
    ShowField="Title" 
    UnlimitedLengthInDocumentLibrary="FALSE" 
    RelationshipDeleteBehavior="None" 
    ID="{$(New-Guid)}" 
    SourceID="{$($list.Id)}" 
    StaticName="Template" 
    Name="Template" 
    ColName="int1" 
    RowOrdinal="0" 
/>
"@
Add-PnPFieldFromXml -List $list -FieldXml $xml

The field definition connects Template to the Site Templates list, displays its Title value, and marks the selection as required. section 11.2.2

When Get-PnPListItem retrieves a SharePoint item, field values are held in a hashtable under internal field names. Ordinary fields such as Title can be simple strings, while lookup fields expose lookup information rather than the final value needed by the automation. A template lookup provides LookupId and LookupValue; the ID can retrieve the selected item from the referenced list. section 11.3.3

Resolve a selected site template

Read the Template value from a Site Requests item, use its LookupId to fetch that item from Site Templates, then read the template item's Name field. This turns the form selection into the internal template name used during site creation. section 11.3.3

$templateItem = Get-PnpListItem -List 'Site Templates' -Id $item['Template'].
LookupId
$templateItem['Name']
SITEPAGEPUBLISHING#0

This retrieval uses the lookup value's LookupId to load the selected template item and obtain its Name value. section 11.3.3

This two-step pattern keeps request entry readable while preserving the implementation value needed later. The requester sees a template title in the form; the automation retrieves the matching internal name before creating the site and recording the resulting URL and status on the request. section 11.2.2 section 11.3.3

How Practical Automation with PowerShell: Effective scripting from the console to the cloud covers it

How deep it goes
Implements field creation through XML and resolves LookupId with a second list-item query, without detailing every XML value.
Examples
Uses Site Requests and Site Templates, displaying template titles and retrieving an internal template name from LookupId.
What it assumes
Assumes PowerShell and SharePoint list automation, while showing lookup-field XML and lookup-value access patterns.
What you can do after
Apply it via PnP PowerShell to create a required lookup field and resolve its selected related-list item.
How it connects
Connects SharePoint lists, PowerShell, PnP PowerShell, XML, Get-PnPListItem, and site creation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Practical Automation with PowerShell: Effective scripting from the console to the cloud. The section links point to the parts of the book it draws on.