I am trying to retrieve managed metadata column (NewsCategory) value in SharePoint 2013 Document library using JSOM. I get "Object Object" rather than actual value.
I tried:-
var newsCat = item.get_item('NewsCategory');
alert(newsCat); //Displays [Object Object]
var newsCatLabel = newsCat.get_label();
var newsCatId = newsCat.get_termGuid();
But, I get the error "Object doesn't support property or method get_label()"
I also tried :-
var newsTags = item.get_item(' NewsCategory ');
for (var i = 0; i < newsTags.get_count() ; i++) {
var newsTag = newsTags.getItemAtIndex(i);
var newsTagLabel = newsTag.get_label();
var newsTagId = newsTag.get_termGuid();
}
Even now I get the error "Object doesn't support property or method get_count()"
I have included " NewsCategory " in the load request:-
context.load(items, 'Include(File, NewsCategory)');
Any idea what the issue is? Do I have to add any *.js file using $.getScript?
I added following .js files
var scriptbase = _spPageContextInfo.webServerRelativeUrl + "/_layouts/15/";
$.getScript(scriptbase + "SP.Runtime.js", function () {
$.getScript(scriptbase + "SP.js", function () {
$.getScript(scriptbase + "SP.Core.js", function () {
});
});
});
Thanks in advance