1

Okay I am fairly sure that I've searched through everything, but I can't seem to figure out how to set a managed metadata value for an item using JSOM in 2010... Why can't we just upgrade to 2013... :(

I checked this answer but it doesn't work for 2010, and I don't understand how to translate the 'ColumnName' and 'TextColumnName' variables from this MSDN article

I know how to lookup my taxonomy items in 2010 using the TaxonomyHiddenList, so I have access to the all the different associated fields.

If you'd like some parameters for an example, I'm trying to assign a list item a managed metadata term with the following info, which is from my TaxonomyHiddenList:

ID: 1
IdForTerm: "6f5fee88-7383-4ba3-a29b-835f9ccee3ed"
IdForTermSet: "e4ee16dc-59c8-4749-bb1d-65538bd20175"
IdForTermStore: "84cbda40-2537-444e-86bb-4f84926de202"
Term: "Term1"
Term1033: "Term1"
Title: "Term1"

My managed metadata field is a multi-value field.

1 Answer 1

1

SP.Taxonomy.TaxonomyFieldValue was introduced in SharePoint 2013 CSOM API, so the example that you mentioned in the question is intended for SharePoint 2013 only.

How to set Managed Metadata field in SharePoint 2010 JSOM

The following example demonstrates how to set single-valued Managed Metadata field value

SP.SOD.executeFunc('SP.js', 'SP.ClientContext', function() {

     var webUrl = _spPageContextInfo.webServerRelativeUrl;
     var listTitle = "<list title>";
     var taxFieldName = "<taxconomy field name>";
     var termLabel = "<term label>";
     var termId = "<term guid>";

     var context = new SP.ClientContext(webUrl);
     var list = context.get_web().get_lists().getByTitle(listTitle);            
     var item = list.getItemById(1);

     var termValue = "-1" + ";#" + termLabel + "|" + termId;
     item.set_item(taxFieldName, termValue);
     item.update();


     context.load(item);
     context.executeQueryAsync(
            function () {
                console.log('Item has been updated: ' + item.get_id());
            }, 
            function (sender, args) {
                 console.log(args.get_message());
            });

});

In case of multi-valued Managed Metadata field, the format of value is:

-1;#<termLabel1>|<termId1>;-1;#<termLabel2>|<termId2>;...-1;#<termLabelN>|<termIdN>
2
  • I thought I had tried this solution -- I found some other stuff that mentioned setting a 'hidden field' value in addition to this one, that's apparently not necessary but what's the deal with that? :)
    – John-M
    Sep 23, 2014 at 14:30
  • Revisiting this: I came across a different list today where I needed to assign the value to a field that had a long random name (mine was i8c02d9873d74d93a7a201363243bf64) instead of the managed metadata field itself (which is just called Topic)
    – John-M
    May 8, 2015 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.