SharePoint Taxonomy Error: Terms can not be shared multiple times in the same term set
So let’s assume you have the following situation. You have two term sets. We will call them TermSetXand TermSetY. In TermSetY, you are reusing a TermX from TermSetX. Now let’s assume that you want to reuse a TermY from TermSetX in TermSetY as a child of TermX.
When I was trying to do this I immediately thought the to use the ReuseTerm method (TaxonomyInternalService.ReuseTerm). ReuseTerm is exposed in the TermSetItem concrete class which is used as by the Term and TermSet derived classes. The utility of ReuseTerm is it allows a specification of a source term that is the target for resuse, and return a new Term from the caller TermSet.
If you try to do this quickly you might end up with code like I did, similar to:
- if(TermSetY.GetTerm(TermY.Id) == null)
- TermX.ReuseTerm(TermY, false);
You may encounter the error:
Error: Microsoft.SharePoint.Taxonomy.TermStoreOperationException: Terms can not be shared multiple times in the same term set
To solve the error, simply lean on the original ReuseTerm method:
- Term termXReference = null;
- if (termSetY.GetTerm(termX.Id) == null)
- termXReference = termSetY.ReuseTerm(termX, false);
- if (termXReference == null) termSetY.GetTerm(termA.Id);
- if(termSetY.GetTerm(termY.Id) == null)
- var termYReference = termXReference.ReuseTerm(termY, false);