0

I need to set field as hidden (not visible on list form) using REST API. I don't know how to setup command.

I found location of this parameter in xml but I don't know how to refer and update them, you can see on screenshots Hidden="TRUE" in <d:Schemaxml> - by default it is "FALSE" - how to update it?

hidden

schema

hidden

1 Answer 1

0

Instead of using REST API, suggest you use CSOM to hide a list content type field.

The demo code for your reference:

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
 
#function to Hide Column From List Content Type in SharePoint Online
Function Hide-ColumnFromContentType()
{
    param
    (
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $ListName,
        [Parameter(Mandatory=$true)] [string] $ContentTypeName,
        [Parameter(Mandatory=$true)] [string] $ColumnName
    )
 
    Try {
        $Cred= Get-Credential
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
 
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials
         
        #Get the List
        $List = $Ctx.Web.Lists.GetByTitle($ListName)
        $Ctx.Load($List)
        $Ctx.ExecuteQuery()
 
        #Get the content type
        $ContentTypes = $List.ContentTypes
        $Ctx.Load($ContentTypes)
        $Ctx.ExecuteQuery()
        $ContentType = $ContentTypes | Where {$_.Name -eq $ContentTypeName}
 
        #Get the Field link from content type
        $FieldLinks =$ContentType.FieldLinks
        $Ctx.Load($FieldLinks)
        $Ctx.ExecuteQuery()
        $FieldLink = $FieldLinks | Where {$_.Name -eq $ColumnName}
 
        #Hide the Field link
        $FieldLink.Hidden = $True
         
        #Update Content type
        $ContentType.update($False)
        $Ctx.ExecuteQuery()
 
        Write-host "Column Hidden from the Content Type Successfully!" -ForegroundColor Green 
    }
    Catch {
        write-host -f Red "Error Hiding Column in Content Type!" $_.Exception.Message
    }
}
 
#Set parameter values
$SiteURL="https://crescent.sharepoint.com"
$ListName="Projects"
$ContentTypeName="Item"
$ColumnName="Priority"
 
#Call the function
Hide-ColumnFromContentType -SiteURL $SiteURL -ListName $ListName -ContentTypeName $ContentTypeName -ColumnName $ColumnName

More information, please refer to the blog.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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