1

While deleting a list column I see an error: Cannot change hidden attribute for this field.

I have changed the Hidden property to False. But still no luck. It keeps on throwing the error.

The script I use to change to Hidden property and then try to delete the column is below:

$Web = Get-SPWeb <url to web>
$List = $web.Lists["Library"]
$SectionField = $List.Fields.GetField("Section")
Write-Host "CanToggleHidden: " $SectionField.CanToggleHidden

$Type = $SectionField.GetType()
$MethodInfo = $Type.GetMethod("SetFieldBoolValue", [System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::Instance)
$MethodInfo.Invoke($SectionField, @("CanToggleHidden", $true))
Write-Host "CanToggleHidden: " $SectionField.CanToggleHidden

$SectionField.Hidden = $false
$SectionField.ReadOnlyField = $false
$SectionField.Sealed = $false
$SectionField.Update()

$Web = Get-SPWeb <url to web>
$List = $web.Lists["Library"]
$SectionField = $List.Fields.GetField("Section")
$SectionField.Delete()

The PowerShell console throws the same error:

enter image description here

Can someone suggest what is wrong with the Field or what other things I need to check?

2 Answers 2

1

Found the real issue. There was nothing wrong with the PowerShell script. Issue was with the field's internal name. The internal name of the field was different than what was being displayed on browser.

I executed some PS command to get the field details, and then is when I found that the field's internal name at list level was different. Then I updated the script with correct field name, executed, and it worked.

0

Check these flags on your field:

$SectionField.AllowDeletion
$SectionField.CanToggleHidden

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.