3

I am trying to get values from a list for different columns like Title ,ID ,Region Where Region is a metadata column .

I am able to get all the values except metadata column values . Pleas tell me how to get it.

Below is my code

while (ListEnumerator.moveNext())
{
    var currentItem = ListEnumerator.get_current();

    var ID = parseInt(currentItem.get_item('ID'));
    var ID = currentItem.get_item('ID');
    var Region = currentItem.get_item('Region');
    alert(Region);              
}

it is giving alert as object object.

  • For Managed Metadata, it matters which version of SharePoint is used – Vadim Gremyachev Feb 13 '14 at 19:45
7

Assume the following Managed Metadata fields:

  • Tags (Multiple Taxonomy Field type)
  • NewsCategory (Taxonomy Field type)

How to retrieve Managed Metadata field via CSOM in SharePoint 2013

SP.Taxonomy.TaxonomyField value is represented as SP.Taxonomy.TaxonomyFieldValue object:

//Get Taxonomy Field value
var newsCat = item.get_item('NewsCategory'); 
var newsCatLabel = newsCat.get_label();
var newsCatId = newsCat.get_termGuid();

Multiple SP.Taxonomy.TaxonomyField value is represented as SP.Taxonomy.TaxonomyFieldValueCollection object

//Get Multiple Taxonomy Field value
var newsTags = item.get_item('Tags'); 
for(var i = 0; i < newsTags.get_count(); i++) {
    var newsTag = newsTags.getItemAtIndex(i);
    var newsTagLabel = newsTag.get_label();
    var newsTagId = newsTag.get_termGuid();

}

How to retrieve Managed Metadata field via CSOM in SharePoint 2010

//Get Taxonomy Field value
var newsCat = item.get_item('NewsCategory'); 
var newsCatParts = newsCat.split('|');  //Format TermLabel|TermId
var newsCatLabel = newsCatParts[0];
var newsCatId = newsCatParts[1];


//Get Multiple Taxonomy Field value
var newsTags = item.get_item('Tags'); 
for(var idx in newsTags) {
      var newsTagsParts = newsTags[idx].split('|');
      var newsTagLabel = newsTagsParts[0];
      var newsTagId = newsTagsParts[1];

}    
  • NOT WORKING I tried below this code as u said var Region = currentItem.get_item('Region'); var newsCatLabel = Region.get_label(); alert(newsCatLabel); – Rameez Feb 13 '14 at 14:17
  • It seems that you are trying to get multiple Multiple Taxonomy Field value, the answer has been updated to reflect this case – Vadim Gremyachev Feb 13 '14 at 19:30
  • Just would like to add that this method of getting the Taxonomy Values is only available in SharePoint 2013. – Vardhaman Deshpande Feb 13 '14 at 20:01
  • indeed, that's why the answer updated to address both versions, thanks mate. – Vadim Gremyachev Feb 13 '14 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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