将列表中的元数据列值复制到Sharepoint Online中的查找列 [英] Copy Metadata Column values in a list to a Lookup Column in Sharepoint Online
本文介绍了将列表中的元数据列值复制到Sharepoint Online中的查找列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个A列,它是一个托管元数据列。我需要将列A值复制到作为查阅列的列B.请指导我如何使用CSOM / powershell脚本实现这一目标。
I have Column A which is a managed metadata column. I need to copy the column A values to Column B which is a lookup column. Kindly guide me how this can be achieved using CSOM/powershell scripts.
任何建议/链接,请分享。
Any suggestions/links, please share.
谢谢!
Adyasha
Adyasha
推荐答案
托管元数据列和查阅列是不同类型对于列,您应该创建托管元数据列而不是查找列。
然后,您可以尝试使用以下CSOM代码复制值。
string UserName = "lee@domain.onmicrosoft.com"; //give your username here
string password = "pw"; //give your password
var secure = new SecureString();
foreach (char c in password)
{
securePassword.AppendChar(c);
}
string SourceSiteCollectionurl = "https://domain.sharepoint.com/sites/tst";
using (var sourceContext = new ClientContext(SourceSiteCollectionurl))
{
sourceContext.Credentials = new SharePointOnlineCredentials(UserName, secure);
List SourceList = sourceContext.Web.Lists.GetByTitle(listName);
Microsoft.SharePoint.Client.ListItem item = SourceList.GetItemById(1);
sourceContext.Load(item);
sourceContext.ExecuteQuery();
TaxonomyFieldValueCollection sourceValue = item["Related_x0020_Party"] as TaxonomyFieldValueCollection;
string[] termValuesarrary;
List<string> termValues = new List<string>();
foreach (TaxonomyFieldValue taxProductFieldValue in sourceValue)
{
termValues.Add(taxProductFieldValue.Label + "|" + taxProductFieldValue.TermGuid);
}
termValuesarrary = termValues.ToArray();
string strtermValues = string.Join(";", termValuesarrary);
List targetList = sourceContext.Web.Lists.GetByTitle("Project Department");
Microsoft.SharePoint.Client.ListItem targetItem = targetList.GetItemById(2);
sourceContext.Load(targetList.Fields);
sourceContext.Load(targetItem);
sourceContext.ExecuteQuery();
targetItem["Related_x0020_Party"] = strtermValues;
targetItem.Update();
sourceContext.Load(targetItem);
sourceContext.ExecuteQuery();
}
以下是供您参考的主题。
最诚挚的问候,
Lee
这篇关于将列表中的元数据列值复制到Sharepoint Online中的查找列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文