【问题标题】:Update SharePoint Online columns/content types with CSOM使用 CSOM 更新 SharePoint Online 列/内容类型
【发布时间】:2014-07-21 21:36:00
【问题描述】:

我有以下 csom 脚本来更新站点列并下推更改:

Add-Type -Path "Libraries\Microsoft.SharePoint.Client.dll" 
Add-Type -Path "Libraries\Microsoft.SharePoint.Client.Runtime.dll" 

$webUrl = "enter_url_here" 
$username = "enter_username_here"
$password = "enter_password_here"
$securePass = ConvertTo-SecureString $password -AsPlainText -Force

$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePass)

#Add description to the "Other category" field
$fieldTitle = "Other category"
$fieldDesc = "Search for an existing name before adding new entries"
$field = $ctx.Site.RootWeb.Fields.GetByInternalNameOrTitle($fieldTitle)
$field.Description = $fieldDesc
$field.UpdateAndPushChanges($true)

#Add description to the "Initiator location" field
$field2Title = "Initiator location"
$field2 = $ctx.Site.RootWeb.Fields.GetByInternalNameOrTitle($field2Title)
$field2.Description = $fieldDesc
$field2.UpdateAndPushChanges($true)

#Setting the "Main-category" field as required/mandatory
$field3Title = "Main-category"
$field3 = $ctx.Site.RootWeb.Fields.GetByInternalNameOrTitle($field3Title)
$field3.Required = $true
$field3.UpdateAndPushChanges($true)

$ctx.ExecuteQuery()

上述字段/列都是称为“主文档”的网站内容类型的一部分。

到目前为止,这工作正常,但是对于“主类别”字段,如何在内容类型级别将其设置为“必需”?目前这仅在网站栏级别设置,实现此目的的最简单方法是什么?

非常感谢。

【问题讨论】:

    标签: powershell sharepoint csom sharepoint-online


    【解决方案1】:

    使用ContentType.FieldLinks property 获取内容类型中的字段引用,然后使用FieldLink.Required property 设置一个值,指定该字段是否需要值。

    示例

    如何通过 Content Type 为字段设置Required 属性:

    $ct = $ctx.Web.ContentTypes.GetById($ctId) #get Content Type 
    $fieldLink = $ct.FieldLinks.GetById($fieldId) #get Field Link
    $fieldLink.Required = $true
    $ct.Update($true)
    $ctx.ExecuteQuery() 
    

    【讨论】:

      猜你喜欢
      • 2014-06-21
      • 1970-01-01
      • 2016-06-19
      • 2017-01-30
      • 2023-03-19
      • 2015-07-09
      • 2017-10-11
      • 2023-04-01
      • 1970-01-01
      相关资源
      最近更新 更多