In this SharePoint PnP tutorial, We will discuss how to solve “Term update failed because of
Recently, I was working with PnP SharePoint in an ASP.NET Web Application in Visual Studio 2017. There, our requirement was to create a term set, terms, etc. for SharePoint global navigation.
Learn SharePoint term store.
If you are new to PnP SharePoint, have a look at this article: SharePoint Online Development using Patterns and Practices (PnP)
To add this term navigation, I have written CSOM code as [childTerm.GetTaxonomyTerm().TermStore.CommitAll();] within the
While I was running this CSOM code, an error occurred as “Term update failed because of
This below CSOM code is what I have written within the foreach() loop.
try
{
foreach (ImportTerms level1TermItem in level1TermItems)
{
childTerm = termCategory.CreateTerm(level1TermItem.Level1Term,
NavigationLinkType.SimpleLink, Guid.NewGuid());
childTerm.SimpleLinkUrl = "/sites/Bhawana/Pages/Product.aspx?c=" +
level1TermItem.Level1Term;
childTerm.GetTaxonomyTerm().TermStore.CommitAll();
ctx.ExecuteQuery();
}
}
catch (Exception ex)
{
}
Term update failed because of save conflict
The Solution of this above error is: You should write the CSOM code [childTerm.GetTaxonomyTerm().TermStore.CommitAll();] outside of the foreach() loop.
Once you will write the above code outside of the loop and again run the code, then it will execute and give the appropriate result.
Follow the below-tested CSOM code:
try
{
foreach (ImportTerms level1TermItem in level1TermItems)
{
childTerm = termCategory.CreateTerm(level1TermItem.Level1Term,
NavigationLinkType.SimpleLink, Guid.NewGuid());
childTerm.SimpleLinkUrl = "/sites/Bhawana/Pages/Product.aspx?c=" +
level1TermItem.Level1Term;
}
childTerm.GetTaxonomyTerm().TermStore.CommitAll();
ctx.ExecuteQuery();
}
catch (Exception ex)
{
}
Term update failed because of save conflict
Another very useful solution I got and it’s a brilliant solution from sadomovalex where I have added the code in a do while loop and it worked perfectly as per the requirement.
So you can put the term store csom code inside a do while loop.
NavigationTerm childTerm = null;
foreach (ImportTerms level1TermItem in level1TermItems)
{
do
{
try
{
childTerm = termBrand.CreateTerm(level1TermItem.Level1Term, NavigationLinkType.SimpleLink, Guid.NewGuid());
childTerm.SimpleLinkUrl = "/sites/Bhawana/Pages/Product.aspx?c=" + level1TermItem.Level1Term;
childTerm.GetTaxonomyTerm().TermStore.CommitAll();
ctx.ExecuteQueryRetry();
break;
}
catch (Exception)
{
}
} while (true);
}
You may like following SharePoint CSOM tutorials:
- Retrieve SharePoint list items programmatically using jsom, rest
api and csom in SharePoint Online/2016/2013 - SharePoint create workflow history list programmatically using
client side object model code (csom) - Create subsite in SharePoint 2016 programmatically using csom visual studio 2017
- SharePoint Online: Activate Workflows can use app permissions Feature programmatically using CSOM
- Retrieve term store data including Labels
using . Net managed object model in SharePoint Online
This SharePoint tutorial, we discussed the solution of an error as “Term update failed because of
I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site EnjoySharePoint.com