Forum Discussion
CSOM Update "Other labels" of a term
Hi,
It looks like modifying the "other labels" using CSOM is not supported. Or at least I did not get it working.
Can somebody explain me how to do it ? Getting the term, loading the "labels collection", updating one label and save ... But nothing is changed when verifying in the term store :-(
Thanks,
Marc Nemegeer
I wrote a quick sample application for you to demonstrate:
using Microsoft.SharePoint.Client.Taxonomy;
using OfficeDevPnP.Core;
namespace TermLabelUpdater
{
class Program
{
static void Main(string[] args)
{
using (var ctx = new AuthenticationManager().GetSharePointOnlineAuthenticatedContextTenant("", "", ""))
{
var taxonomySession = TaxonomySession.GetTaxonomySession(ctx);
var termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
var termGroup = termStore.Groups.GetByName("Test");
var termSet = termGroup.TermSets.GetByName("Test");
var term = termSet.Terms.GetByName("Test");
ctx.Load(term, t => t.Labels);
ctx.ExecuteQuery();
var label = term.Labels[2];
label.Value = "UPDATE!";
termStore.CommitAll();
ctx.ExecuteQuery();
}
}
}
}
3 Replies
- paulpaschaBronze Contributor
I wrote a quick sample application for you to demonstrate:
using Microsoft.SharePoint.Client.Taxonomy;
using OfficeDevPnP.Core;
namespace TermLabelUpdater
{
class Program
{
static void Main(string[] args)
{
using (var ctx = new AuthenticationManager().GetSharePointOnlineAuthenticatedContextTenant("", "", ""))
{
var taxonomySession = TaxonomySession.GetTaxonomySession(ctx);
var termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
var termGroup = termStore.Groups.GetByName("Test");
var termSet = termGroup.TermSets.GetByName("Test");
var term = termSet.Terms.GetByName("Test");
ctx.Load(term, t => t.Labels);
ctx.ExecuteQuery();
var label = term.Labels[2];
label.Value = "UPDATE!";
termStore.CommitAll();
ctx.ExecuteQuery();
}
}
}
}- Marc NemegeerBrass Contributor
Ok, thanks for the support. Beginners error, did not have the "commit all". Thanks for helping me out :-)
Best regards,
Marc
- paulpaschaBronze Contributor
Modifying Term Labels using CSOM should work just fine. Please make sure you call TermStore.CommitAll() followed by ClientContext.ExecuteQuery() to save your changes. If you don't already have one, you can get a reference to TermStore from your Term object... (term.TermStore)
Hope this helps!