I’ve been working lately on a project that requires access to the Managed Metadata Service in SP2010. I got to a point where I needed to add a term to the default term store under a term set.
I have some code in my project that takes in the following parameters and creates a term in the term store:
– TaxonomyClientService proxy instance
– Term name
– Term store ID
– Term Set ID
I needed to use the AddTerm method of the proxy to create a new term, and spent most of my afternoon wrestling with the format of the NewTerms parameter of the method.
The following MSDN documentation is wrong! (here) – or at least not informative.
The MSDN documentation stipulates to use NewTerm nodes to wrap new terms in the XML passed to the service. What the documentation did not tell me was:
1. The term set must be open, otherwise the method returns an empty string.
2. The method need the exact syntax for the XML to work – looking on the web, I found no real answer to this problem, and ended up reflecting the web service code to get my answer. Below is a sample piece of XML.
<newTerms><newTerm label="MyTerm" clientId="1" parentTermId="GUID of parent or empty GUID if none"></newTerm></newTerms>
Worth noting with the above XML…
1. Notice the lowercase use of newTerms and newTerm (not uppercase N as in the MSDN documentation)
2. clientId does very little and so you can pass the value 1
3. The parentTermId must be a real GUID, and Guid.Empty if no parent
4. New terms wrap in the newTerms node, which MSDN failed to mention.
I hope this post saves others an afternoon worth of work, which it cost me.