Question

Below is a part of a very long powershell script I have:

Add-PnpField  -List $ListName -DisplayName “Title • Function” -InternalName “TitleFunction” -Type Choice -Choices “Account Executive”,”Vice President”,”Digital Planner”

$field = Get-PnpField -List $ListName -Identity “Title • Function”
$field.**(Something)**.FillInChoice = $true
$field.update()

The second part does not work. I've tried a bunch of stuff. I'd just like to tick on "FillInChoice" which appears in the items SchemaXML but does not appear to be quickly editable.

Thoughts? I work well with the Pnp stuff but not so much beyond that.

Était-ce utile?

La solution

The PnP Powershell currently doesn't support FillInChoice property. So, you need to use CSOM code with powershell.

Basically, we are type casting the Field to Field Choice and then updating the property.

Try and modify the below powershell as per your list name and column:

$path = "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\"
Add-Type -Path (Resolve-Path "$($path)Microsoft.SharePoint.Client.dll")
Add-Type -Path (Resolve-Path "$($path)Microsoft.SharePoint.Client.Runtime.dll")

$siteUrl = "https://sitecollectionurl"
$username = "user.name@tenant.onmicrosoft.com"
$password = "password"

$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$ctx.RequestTimeOut = 1000 * 60 * 10;
$ctx.AuthenticationMode = [Microsoft.SharePoint.Client.ClientAuthenticationMode]::Default
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
$ctx.Credentials = $credentials
$web = $ctx.Web
$ctx.Load($web)
$ctx.ExecuteQuery()

$List = $ctx.Web.Lists.GetByTitle("ListName")
$ctx.Load($List)
$ctx.ExecuteQuery()

#Retrieve field
$field = $List.Fields.GetByInternalNameOrTitle("TitleFunction");

#type casting field as Choice field
$fieldChoice = [Microsoft.SharePoint.Client.ClientContext].GetMethod("CastTo").MakeGenericMethod([Microsoft.SharePoint.Client.FieldChoice]).Invoke($ctx,$field)

$ctx.Load($fieldChoice)
$ctx.ExecuteQuery()

#setting the FillInChoice property
$fieldChoice.FillInChoice = $true
$fieldChoice.Update()
$ctx.Load($fieldChoice)
$ctx.ExecuteQuery()

Ensure that the above dll files are present. If you have a different path, please modify accordingly.

If these dll files are not present, please install the SharePoint Online CSOM SDK and change the path as per your file system.

Download link - SPO CSOM SDK

Autres conseils

Try this. Weird I know but it worked for me.

$choice.FillInChoice = "False"
$choice.Update();
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top