0
votes

I am working on Sharepoint 2013 site, I need to manually add value to metadata column "Network" in Library "Drop Off Library". I check if a particular word in present in the document and then I try to update the item. When I try updating "Network" column and other Choice column "PickUp". My metadata column does not get updated but Choice Column gets updated. Below is my code. Please note I am using CSOM.

foreach (Microsoft.SharePoint.Client.ListItem item in ItemCol)
                {
foreach(Term Tstring in termColl)
                        {
                            object findText = Tstring.Name;
                            word.Selection.Find.ClearFormatting();
                            if (word.Selection.Find.Execute(ref findText,
                                ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                                ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                                ref missing, ref missing))
                            {

                                item.File.CheckOut();
                                item["Network"] = "3;#Cartoon"; //My term:cartoon with 3 as term id(checked in TaxonomyHiddenList)
        item["PickUp"] = "Yes";
                                item.Update();
                                context.Load(item);
                                lists.Update();
                                context.ExecuteQuery();
                                item.File.CheckIn("Done", CheckinType.MajorCheckIn);
}
}
1

1 Answers

0
votes

I solved it using below code

if (word.Selection.Find.Execute(ref findText,
                                ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                                ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                                ref missing, ref missing))
                            {
item.File.CheckOut();
                                    TaxonomyFieldValue termValue = null;
                                    TaxonomyField txField = context.CastTo<TaxonomyField>(lists.Fields.GetByTitle("Network"));
                                    termValue = new TaxonomyFieldValue();
                                    termValue.Label = Tstring.Name;
                                    termValue.TermGuid = Tstring.Id.ToString();
                                    termValue.WssId = -1;
                                    txField.SetFieldValueByValue(item, termValue);
                                    item["GetMetadata"] = "Yes";
                                    item.Update();
                                    item.File.CheckIn("Done", CheckinType.MajorCheckIn);
                                    context.Load(item);
                                    context.ExecuteQuery();
}