Я пытаюсь установить значение таксономического поля Sharepoint 2013 таксономического поля в CSOM, но когда я выполняю последнее context.ExecuteQuery()
, после taxField.Update()
исключение вызывается который читает «Первое случайное исключение типа« Microsoft.SharePoint.Client.ServerException »произошло в Microsoft.SharePoint.Client.Runtime.dll Дополнительная информация: значение не может быть нулевым. Имя параметра: termId '. Все загружается отлично, он находит этот термин, и у меня нет идей.При добавлении значений таксономии через CSOM Exception «Значение не может быть равно null. ParamterName: termId» thrown
public void AddTaxonomyFieldValue(ClientContext context, ListItem item, string destinationColumn, IEnumerable<string> terms, Guid termGroupId, Guid termSetId, int lcid)
{
var taxonomySession = TaxonomySession.GetTaxonomySession(context);
var store = taxonomySession.TermStores.GetByName("Managed Metadata Service2");
var group = store.GetGroup(termGroupId);
var set = group.TermSets.GetById(termSetId);
var existingTerms = set.GetAllTerms();
var field = item.ParentList.Fields.GetByInternalNameOrTitle(destinationColumn);
var taxField = context.CastTo<TaxonomyField>(field);
context.Load(existingTerms, et => et.Include(t => t.Labels.Include(l => l.Value, l => l.Language), t => t.Id, t=> t.PathOfTerm, t => t));
context.ExecuteQuery();
var fieldTermValues = new Collection<Term>();
foreach (var term in terms)
{
var lmi = new LabelMatchInformation(context);
lmi.TermLabel = term;
// Find existing term
var existingTerm =
existingTerms.FirstOrDefault(t => t.Labels.Any(l => l.Language == lcid && l.Value == term));
if (null == existingTerm)
{
// create new term
existingTerm = set.CreateTerm(term, lcid, new Guid());
set.TermStore.CommitAll();
context.Load(existingTerm);
context.ExecuteQuery();
}
fieldTermValues.Add(existingTerm);
}
// set taxonomy field
taxField.SetFieldValueByCollection(item, fieldTermValues, lcid);
taxField.Update();
// Exception Thrown Here
context.ExecuteQuery();
}
EDIT 1: Я только заметил, что термин таксономии я создал в этом цикле Еогеасп имеет уникальный идентификатор == «00000000-0000-0000-0000-000000000000», если смотреть на него с Sharepoint сайт. Поэтому я думаю, что моя проблема лежит там.