I hid some list level fields from the edit form of a Document Set by setting ShowInEditForm to false via the management shell. I now want to add them back to the edit form. I've changed ShowInEditForm to true at both the list and content type level, called Update on the list and spweb, but when I edit an item the fields still don't show up.
1 Answer
as you have mentioned that you have tried doing at Content Type level, which means column is a site column. And here is the PowerShell function which will set column's appearance in Edit/New form.
Function is csom PowerShell so it does not depend whether you need to run on server, just pass valid parameters $Url = your site url, $credentials = your login/password to your site(admin), $FieldInternalName = Internal name of site column
function ShowHideFields()
{
param(
[Parameter(Mandatory=$true)][string]$url,
[Parameter(Mandatory=$true)][System.Net.NetworkCredential]$credentials,
[Parameter(Mandatory=$true)][string]$FieldInternalName
)
begin{
try
{
#get Client Object
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$Context.Credentials = $Credentials
#Load web object
$web = $Context.Web
$fields = $Context.Site.RootWeb.Fields;
$Context.Load($web)
$Context.Load($fields)
$Context.ExecuteQuery()
}
catch
{
Write-Host "Error while getting context. Error -->> " + $_.Exception.Message -ForegroundColor Red
}
}
process{
try
{
Write-Host "Update the site column" $FieldInternalName -ForegroundColor Cyan
try
{
$field = $fields.GetByInternalNameOrTitle($FieldInternalName)
#$true to show and $false to hide, Show/Hide fields as per your requirement.
#
$field.SetShowInEditForm($false)
$field.SetShowInNewForm($false)
#Update and push changes where ever it is used..
#
$field.UpdateAndPushChanges($true)
$Context.Load($field)
$Context.ExecuteQuery()
Write-Host "Site column" $FieldInternalName " will now not be shown in New and Edit oob forms" -ForegroundColor Cyan
}
catch
{
Write-Host "Site column" $FieldInternalName " does not exist in the list of site collection columns" -ForegroundColor Cyan
return
}
}
catch
{
Write-Host ("Error -->> " + $_.Exception.Message) -ForegroundColor Red
}
}
end{
$Context.Dispose()
}
}