SharePoint自动化系列——Set MMS field value using PowerShell.
转载请注明出自天外归云的博客园: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的赋值方法,欢迎大家提问与交流。
相关文章
- 【Python从入门到精通】(八)Python中的set集合(每个人都是唯一的个体)
- java中Set,Map,Stack一些简单用法
- Python:Set union() 方法
- mysql find_in_set逗号隔开字符串查询包含某个值或某些值中某值
- java:List、Map、Set默认初始容量和扩容增量及加载因子 & 内存泄漏 & 线程安全
- Vue中Vue.set()和this.$forceUpdate()的使用
- JSTL标签用法:<c:choose><c:forEach><c:if><c:when><c:set>
- [Jetson] How to set up it.
- MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error
- shell脚本中的set -e和set -o pipefail
- TypeScript set和get
- CF1041B Buying a TV Set
- 【JS ES6】了解学习set类型和weakset类型