none
Sharepoint PNP Lookup List not dropping down. RRS feed

  • Question

  • I'm attempting to use SharePoint PNP powershell commands to create content types and add them to a list.  All the commands appear to work however after inspecting the site, some of the lookups I created will not drop down.  On one of them I dropped the list and recreated in the GUI and added the content type back and the drop down worked.

    Is there an issue with adding content types with drop downs through SharePoint PNP?  Perhaps my code is wrong.

    ###############################
    ##
    ##  Customers
    ## 
    
    <#
    Customers List
    'Customer'
        'Title'
        'CAR Priority'
    #>
    #Remove-PnPList -Identity 'Customers'
    
    #Add Content Type
    $itemContentType = Get-PnPContentType -Identity Item
    Add-PnPContentType -Name 'Customer' -Description 'Customer Name' -Group 'QA Content Types' -ParentContentType $itemContentType
    
    #Add Site Columns
    Add-PnPField -DisplayName "CAR Priority" -InternalName "carPriority" -Type Number -Group 'QA Columns'
    Add-PnPFieldToContentType -Field "CAR Priority" -ContentType 'Customer'
    
    #Create List
    New-PnPList -Template GenericList -Title 'Customers' -OnQuickLaunch
    
    #Add Content Type to List
    Add-PnPContentTypeToList -List 'Customers' -ContentType 'Customer'
    #Rename Title Field
    Set-PnPField -List 'Customers' -Identity 'Title' -Values @{Title = "Customer"}
    
    #Update view
    Set-PnPView -List 'Customers' -Identity 'All Items' -Fields "Customer","CAR Priority"
    
    #Remove the Item Content Type
    Remove-PnPContentTypeFromList  -List 'Customers' -ContentType 'Item'
    
    ##
    ##  Customers
    ## 
    ###############################
    
    ###############################
    ##
    ##  Customer Locations
    ## 
    <# 
    
    #>
    
    #Add Content Type
    $itemContentType = Get-PnPContentType -Identity Item
    Add-PnPContentType -Name 'Customer Location' -Description 'Customers Location' -Group 'QA Content Types' -ParentContentType $itemContentType
    
    #Create Customer Lookup
    $customersList = Get-PnPList -Identity 'Customers'
    $customerField = Get-PnPField -List $customersList.Id -Identity "Customer"
    $web = Get-PnPWeb
    [xml]$xmldata = "<Field
        Type=""Lookup""
        ID=""{$(New-Guid)}""
        Name=""customer""
        DisplayName=""Customer""
        StaticName=""customer""
        List=""{$($customersList.Id.Guid)}""
        WebId=""$($web.Id.Guid)""
        SourceID=""{$($web.Id.Guid)}""
        ShowField=""Customer""
        UnlimitedLengthInDocumentLibrary=""FALSE""
        Required=""FALSE""
        EnforceUniqueValues=""FALSE""
        Group=""QA Columns""
    />"
    Add-PnPFieldFromXml -FieldXml $xmldata.OuterXml
    
    #Add lookup column to content type
    Add-PnPFieldToContentType -Field "Customer" -ContentType 'Customer Location'
    
    #Create List
    New-PnPList -Template GenericList -Title 'Customer Locations' -OnQuickLaunch
    
    #Add Content Type to List
    Add-PnPContentTypeToList -List 'Customer Locations' -ContentType 'Customer Location'
    #Rename Title Field
    Set-PnPField -List 'Customer Locations' -Identity 'Title' -Values @{Title = "Customer Location"}
    
    #Update view
    Set-PnPView -List 'Customer Locations' -Identity 'All Items' -Fields "Customer Location","Customer"
    
    #Remove the Item Content Type
    Remove-PnPContentTypeFromList  -List 'Customer Locations' -ContentType 'Item'
    
    ##
    ##  Customer Locations
    ## 
    ###############################

    I know I need to polish up the XML data.  I'm thinking this is where the issue is.  It's been difficult to find all the settings required for a lookup.


    David Jenkins



    Thursday, October 31, 2019 1:46 PM

Answers

  • I think it was not using the internal name.

    #Create Customer Lookup
    $customersList = Get-PnPList -Identity 'Customers'
    $customerField = Get-PnPField -List $customersList.Id -Identity "Customer"
    $web = Get-PnPWeb
    [xml]$xmldata = "<Field
        Type=""Lookup""
        ID=""{$(New-Guid)}""
        Name=""$($customerField.Title.ToLower())""
        DisplayName=""$($customerField.Title)""
        StaticName=""$($customerField.Title.ToLower())""
        List=""{$($customersList.Id.Guid)}""
        WebId=""$($web.Id.Guid)""
        SourceID=""{$($web.Id.Guid)}""
        ShowField=""$($customerField.InternalName)""
        UnlimitedLengthInDocumentLibrary=""FALSE""
        Required=""FALSE""
        EnforceUniqueValues=""FALSE""
        Group=""QA Columns""
    />"
    Add-PnPFieldFromXml -FieldXml $xmldata.OuterXml


    David Jenkins

    Thursday, October 31, 2019 1:55 PM

All replies

  • I think it was not using the internal name.

    #Create Customer Lookup
    $customersList = Get-PnPList -Identity 'Customers'
    $customerField = Get-PnPField -List $customersList.Id -Identity "Customer"
    $web = Get-PnPWeb
    [xml]$xmldata = "<Field
        Type=""Lookup""
        ID=""{$(New-Guid)}""
        Name=""$($customerField.Title.ToLower())""
        DisplayName=""$($customerField.Title)""
        StaticName=""$($customerField.Title.ToLower())""
        List=""{$($customersList.Id.Guid)}""
        WebId=""$($web.Id.Guid)""
        SourceID=""{$($web.Id.Guid)}""
        ShowField=""$($customerField.InternalName)""
        UnlimitedLengthInDocumentLibrary=""FALSE""
        Required=""FALSE""
        EnforceUniqueValues=""FALSE""
        Group=""QA Columns""
    />"
    Add-PnPFieldFromXml -FieldXml $xmldata.OuterXml


    David Jenkins

    Thursday, October 31, 2019 1:55 PM
  • Hi David L. Jenkins, 

    It is very happy that you have resolved your problem.

    Thank you for your sharing and it will help others have the same issue.

    Best regards,

    Sara Fan

    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Friday, November 1, 2019 6:15 AM
    Moderator