SharePoint自动化系列——Set MMS field value using PowerShell.

简介: 转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 本章将总结一下设置SharePoint list中item的Managed Metadata field value的方法。

转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/

本章将总结一下设置SharePoint list中item的Managed Metadata field value的方法。

以下函数是我封装好的可以直接用来获取相应Managed Metadata类型field的terms value:

Add-PSSnapin Microsoft.SharePoint.PowerShell
function GetFieldTerms
{
  param($siteUrl,$listTitle,$fieldName)
  $site = Get-SPSite $siteUrl
  $web = $site.rootweb
  $List = $web.lists[$listTitle]
  $MMSField = $List.Fields[$fieldName]
  $MMSFieldtsId = $MMSField.TermSetId
  $MMSFieldtermStoreId = $MMSField.SspId
  $MMSFieldtsession = Get-SPTaxonomySession -Site $site
  $MMSFieldtstore = $MMSFieldtsession.TermStores[$MMSFieldtermStoreId]
  $MMSFieldtset = $MMSFieldtstore.GetTermSet($MMSFieldtsId)
  $terms = $MMSFieldtset.terms
  $terms
}

该函数的返回值为$terms,所以在使用的过程中可以将该结果存储到你所需要保存到的变量中,使用方法如下(引号中是需要你去填写的数据):

$terms = GetFieldTerms -siteUrl "" -listTitle "" -fieldName ""

在PowerShell中运行的结果如下,我们可以看到,相应的terms都已经保存到我们的变量$terms中:

接下来,就是将获取到的terms的值赋予到SharePoint list item相应field的过程(与正常的赋值过程不同):

#正常field的赋值方法:
$Item["fieldName"] = $value
#MMS类型field的赋值方法($index为$terms数组变量中相应位置的索引): $list.fields[
"fieldName"].SetFieldValue($Item,terms[$index])

以后陆续我还会总结一些其他类型field的赋值方法,欢迎大家提问与交流。

相关文章
|
7月前
|
JavaScript API
【Vue】Cannot set reactive property on undefined,null,or primitive value:undefined
【Vue】Cannot set reactive property on undefined,null,or primitive value:undefined
103 0
|
消息中间件 Kafka
Cannot set the value of read-only property ‘additionalSourceDirs‘ for task ‘:jacocoRootReport‘ of
这个问题是gradle的build版本问题,我是在build kafka的老版本时报的错,这个问题我查了一遍网上的内容,发现很多博客忽略了IDEA settings关于gradle的build的一个配置。
339 0
Cannot set the value of read-only property ‘additionalSourceDirs‘ for task ‘:jacocoRootReport‘ of
debian samba出错:set_variable_helper(yes ): value is not boolean!
debian samba出错:set_variable_helper(yes ): value is not boolean!
160 0
成功解决pandas\core\indexing.py:179: SettingWithCopyWarning: A value is trying to be set on a copy of a
成功解决pandas\core\indexing.py:179: SettingWithCopyWarning: A value is trying to be set on a copy of a
|
SQL 关系型数据库 MySQL
MySQL运行SQL:[ERR] 1231 - Variable ‘time_zone‘ can‘t be set to the value of ‘NULL‘
MySQL运行SQL:[ERR] 1231 - Variable ‘time_zone‘ can‘t be set to the value of ‘NULL‘
1633 0

热门文章

最新文章