TaxonomyClient and AddTerms method

Jan 27, 2012 at 8:04 AM

Hi,

first of all thanks for sharing this, and incredible job that is saving me a lot of time. I wanted to ask you one question. I'm trying to add a term to the managed metadata service by using the AddTerms method and I'm using this code:

    var xmlTerms = "";

    for (i = 0; i < terms.length; i++) {
        xmlTerms += "&lt;newTerm label='" + terms[i] +"' clientId='" + guid() + "' parentTermId='00000000-0000-0000-0000-000000000000'/&gt;"
    }
    
    $().SPServices({
        operation: "AddTerms",
        sharedServiceId: taxconfig.SspId,
        termSetId: taxconfig.TermSetId,
        lcid: 1033,
        newTerms: xmlTerms,
        completefunc: function (xData, Status) {

        },
    });

I'm getting "success" as the status of the operation but this is the content of the xData object:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<AddTermsResponse xmlns="http://schemas.microsoft.com/sharepoint/taxonomy/soap/">
<AddTermsResult>&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;TermStore /&gt;
</AddTermsResult></AddTermsResponse></soap:Body></soap:Envelope>

As you can see, the contents of AddTermsResult is an empty TermStore node. The termset is set to open. I can add terms to the same termset by using server side code.

Can you give me any hint on what's going on?

Thanks in advance!

May 28, 2012 at 6:16 PM

Hi David,

I am trying to get this function to work also, with different bad results. Did you ever get it to work?

/Peter

Oct 3, 2013 at 7:03 AM
Did any one get it to work?
Mar 17, 2014 at 10:52 PM
Thanks David and Peter for getting me on the right track, I know this is a long time since you guys posted, but I had a hard time getting it to work so figured I will post it for everyone else.

(Other thread that led me here: https://spservices.codeplex.com/discussions/357348)

This link is what I consider the only useful documentation from Microsoft on this topic:
http://msdn.microsoft.com/en-us/library/dd958731(v=office.12).aspx

What you are missing is an encoded "<newTerms>" inside the "<newTerms>"

Here is a complete request that works for me:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>

<AddTerms xmlns="http://schemas.microsoft.com/sharepoint/taxonomy/soap/">
    <sharedServiceId>0d18c636-63d4-452b-b094-6de97ee5159d</sharedServiceId>
    <termSetId>48508451-17d5-4bdb-b1c9-7f096f680352</termSetId>
    <lcid>1033</lcid>
    <newTerms>&lt;newTerms&gt;&lt;newTerm label=&quot;Test Root&quot; clientId=&quot;1&quot; parentTermId=&quot;00000000-0000-0000-0000-000000000000&quot; &gt;&lt;/newTerm&gt;&lt;/newTerms&gt;</newTerms>
</AddTerms>

</soapenv:Body></soapenv:Envelope>
Response:
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><AddTermsResponse xmlns="http://schemas.microsoft.com/sharepoint/taxonomy/soap/"><AddTermsResult>&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;TermStore&gt;&lt;T a9="ccbd12f6-61e1-4a01-9cf4-c9fa8685a3ca" a21="false" a61="1"&gt;&lt;LS&gt;&lt;TL a32="Test Root" a31="true" /&gt;&lt;/LS&gt;&lt;DS /&gt;&lt;TMS&gt;&lt;TM a24="48508451-17d5-4bdb-b1c9-7f096f680352" a12="Site / Location" a40="" a17="true" a67="" a45="ccbd12f6-61e1-4a01-9cf4-c9fa8685a3ca" /&gt;&lt;/TMS&gt;&lt;/T&gt;&lt;/TermStore&gt;</AddTermsResult></AddTermsResponse></soap:Body></soap:Envelope>