0

Inside the content type I set a field as required inside my SharePoint online site as follow:- enter image description here

and using PnP i set the field to be hidden in new form, as follow:-

PS C:\WINDOWS\system32> $ctx = Get-PnPContext
PS C:\WINDOWS\system32> $field = Get-PnPField -Identity "LineManager"
PS C:\WINDOWS\system32> $field.SetShowInNewForm($false)
PS C:\WINDOWS\system32> $field.UpdateAndPushChanges($true)
PS C:\WINDOWS\system32> $ctx.ExecuteQuery()

now when i add a new item inside the list i thought that i will get an error since the new form is missing a required field, but i was able to save the item even if the new form is missing a required filed.. so can anyone advice how SharePoint handle this?

1
  • Hidden columns are not rendered on the form (data entry/edit) and that's why validation on those columns is not performed when the form is submitted. Sep 30, 2020 at 20:42

1 Answer 1

0

SetShowInNewForm($false) does not change the column status to "hidden", its status is still shown as Required in the content type.

PnP PowerShell to Hide a Field at Content Type Level:

#Config Variables
$SiteURL = "https://crescenttech.sharepoint.com"
$ContentTypeName ="Crescent Project V2"
$FieldName = "ProjectManager" #Internal Name
 
#Connect to PNP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
 
#Get the Client Context
$Context = Get-PnPContext
  
#Get the content type
$ContentType = Get-PnPContentType -Identity $ContentTypeName -ErrorAction Stop
  
#Get the Field from Content Type
$ContentTypeField = $ContentType.Fields.GetByInternalNameOrTitle($FieldName)
$Context.Load($ContentTypeField)
$Context.ExecuteQuery()
  
#Set Hidden Property of the field
$ContentType.FieldLinks.GetById($ContentTypeField.Id).Hidden = $True
$ContentType.Update($True) #Update Children
$Context.ExecuteQuery()
Write-host -f Green "Field '$($ContentTypeField.Title)' Set to Hidden!"
4
  • thanks for the reply, but your answer is not related to my question
    – John John
    Oct 1, 2020 at 9:09
  • Like Matiur Ra​​hman said, when you run SetShowInNewForm($false), this still makes the column required, it just doesn't display in the form, so you need to set the hidden property of the field to make the error disappear.
    – Julie_MSFT
    Oct 2, 2020 at 7:06
  • but i am not getting any error, i am asking a different question
    – John John
    Oct 2, 2020 at 9:16
  • I know you could save the new item, however there is a required filed notification in red in that item, I have tested it and has the same result with you, so I say SetShowInNewForm($false) not solve the issue of required filed.
    – Julie_MSFT
    Oct 5, 2020 at 1:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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