PnP-PowerShell icon indicating copy to clipboard operation
PnP-PowerShell copied to clipboard

Set-PnPField - Not able to set all fields.

Open jagrock opened this issue 8 years ago • 3 comments

###Notice: many issues / bugs reported are actually related to the PnP Core Library which is used behind the scenes. Consider carefully where to report an issue:###

  1. Are you using Apply-SPOProvisioningTemplate or Get-SPOProvisioningTemplate? The issue is most likely related to the Provisioning Engine. The Provisioning engine is not located in the PowerShell repo. Please report the issue here: https://github.com/officedev/PnP-Sites-Core/issues.
  2. Is the issue related to the cmdlet itself, its parameters, the syntax, or do you suspect it is the code of the cmdlet that is causing the issue? Then please continue reporting the issue in this repo.
  3. If you think that the functionality might be related to the underlying libraries that the cmdlet is calling (We realize that that might be difficult to determine), please first double check the code of the cmdlet, which can be found here: https://github.com/OfficeDev/PnP-PowerShell/tree/master/Commands. If related to the cmdlet, continue reporting the issue here, otherwise report the issue at https://github.com/officedev/PnP-Sites-Core/issues

Reporting an Issue or Missing Feature

More likely a missing feature than an issue

Expected behavior

To be able to set all fields for a SP Field object.

Actual behavior

Getting error when trying to set some fields, in this case specifically trying to change the field displaytype.

Example Errors/Warning: WARNING: No property 'FriendlyDisplayFormat' found on this field. Value will be ignored. WARNING: No property 'Format' found on this field. Value will be ignored. WARNING: No property 'DisplayFormat' found on this field. Value will be ignored.

Steps to reproduce behavior

Please include complete code samples in-line or linked from gists

Set-PnPField -List $pnpList -Identity $pnpField.ID -Values @{DisplayFormat = "DateOnly";Format = "DateOnly"; FriendlyDisplayFormat = "Disabled"}

Which version of the PnP-PowerShell Cmdlets are you using?

  • [ ] PnP PowerShell for SharePoint 2013
  • [ ] PnP PowerShell for SharePoint 2016
  • [x] PnP PowerShell for SharePoint Online

What is the version of the Cmdlet module you are running?

(you can retrieve this by executing Get-Module -Name *pnppowershell* -ListAvailable) confirmed on: 3.0.1808.0 2.28.1807.0

How did you install the PnP-PowerShell Cmdlets?

  • [ ] MSI Installed downloaded from GitHub
  • [x] Installed through the PowerShell Gallery with Install-Module
  • [ ] Other means

jagrock avatar Aug 07 '18 04:08 jagrock

Got similar issue. Solved using below commands

$field=Get-PnPField -List $listName -Identity $fieldName -web $web $castedDateField =[Microsoft.SharePoint.Client.ClientContext].GetMethod("CastTo").MakeGenericMethod([Microsoft.SharePoint.Client.FieldDateTime]).Invoke($ctx, $field) $castedDateField.FriendlyDisplayFormat = [Microsoft.SharePoint.Client.DateTimeFieldFriendlyFormatType]::Disabled $castedDateField.Update() $ctx.ExecuteQuery()

prafullapatil avatar Feb 13 '19 06:02 prafullapatil

Similar issue again for me.

In my case I had a field of type Hyperlink or Picture aka URL. I wanted this to display as an image rather than as a hyperlink (which is the default). So like @jagrock I wanted to programmatically update the DisplayFormat property, and got the same error when using Set-PnPField.

@prafullapatil Thank you, I was able to adapt your snippet.

$picture = Get-PnPField -List $title -Identity "Picture"
$ctx = (Get-PnPConnection).CloneContext($site)
$castedDisplayFormatField =[Microsoft.SharePoint.Client.ClientContext].GetMethod("CastTo").MakeGenericMethod([Microsoft.SharePoint.Client.FieldUrl]).Invoke($ctx, $picture)
$castedDisplayFormatField.DisplayFormat = [Microsoft.SharePoint.Client.UrlFieldFormatType]::Image
$castedDisplayFormatField.Update()
$ctx.ExecuteQuery()

preavy avatar Mar 27 '19 12:03 preavy

This is tidier

$picture = Get-PnPField -List $title -Identity "Picture"
$picField = $picture.TypedObject
$picField.DisplayFormat = [Microsoft.SharePoint.Client.UrlFieldFormatType]::Image
$picField.Update()

preavy avatar Apr 08 '19 10:04 preavy