Using Add-PnPField to add a calculated site column won't calculate correctly(Get text of a referenced choice field) but instead returns 0 on every item
- Are you using
Apply-PnPProvisioningTemplateorGet-PnPProvisioningTemplate? no. - 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? probably
- If you think that the functionality might be related to the underlying libraries that the cmdlet is calling (We realize that might be difficult to determine), please first double check the code of the cmdlet, which can be found here: https://github.com/pnp/PnP-PowerShell/tree/master/Commands.
Reporting an Issue or Missing Feature
Issue
Expected behavior
Add a calculated column as a site column with the Add-PnPField command that refers to another site column that is a choice type and then use that column (add to content type) in a custom content type(manually or with Add-PnPFieldToContentType) on a list (The choice column is also a site column used in the same content type). After creating a list view that shows that newly created column, make sure the new column is selected on your list view. The result of the calculated column should just be the text of the referenced choice field.
Actual behavior
The calculated column shows to have a value of 0 rather than the other referenced choice column as text. Also after running the command and trying to edit any item on the list and save, you get this error: "Sorry, something went wrong. Cannot complete this action. Please try again."
Steps to reproduce behavior
Make sure you have a site column that is has the type of choice that is used in the content type being used on your list. In This scenario it is called "SomeOtherChoiceField".
Run the PnP powershell command:
Connect-PnPOnline "https://mysite.sharepoint.com" -CurrentCredentials
Add-PnPField -Type Calculated -InternalName "C1" -DisplayName "C1" -Formula ="[SomeOtherChoiceField]"
Manually add the field to the content type you'll be using on your list or use Add-PnPFieldToContentType.
Check the list with a view that includes the choice column as well as the new calculated column.
Which version of the PnP-PowerShell Cmdlets are you using?
- [ ] PnP PowerShell for SharePoint 2013
- [x ] PnP PowerShell for SharePoint 2016
- [ ] PnP PowerShell for SharePoint 2019
- [ ] PnP PowerShell for SharePoint Online
What is the version of the Cmdlet module you are running?
SharePointPnPPowerShell2016 3.18.2002.0 Also tried with version 3.22.2006.2
How did you install the PnP-PowerShell Cmdlets?
- [ ] MSI Installed downloaded from GitHub
- [x ] Installed through the PowerShell Gallery with Install-Module
- [ ] Other means
Please let me know of any questions needed for this. Thanks!
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
My current work around was to use plain CSOM in my powershell script to add the calculated site column and that worked.