1

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.

1

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

  • Am I able to skip the vast majority of the code and instead do something like: $field = Get-PnpField -List $listName -Identity $fieldName ???[br]I did that and it did not work, seemingly because of the .ctx requested in the Invoke. – Joe Fedorowicz Nov 1 '17 at 13:26
  • @JoeFedorowicz - it wont work, please see my edited answer. You need to only modify the site collection url, list name and the internal column name in the above code. It will work as is :) – Gautam Sheth Nov 1 '17 at 15:30
  • Hi I eventually got there with a few tweaks on your code. Thanks a lot. – Joe Fedorowicz Nov 2 '17 at 12:15
0

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

$choice.FillInChoice = "False"
$choice.Update();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.