I have a managed metadata type column in my document library. I need to get the data from this column by using jsom. But whenever I try to get the values it gives me error. The code and error are given below:
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle(docLibName);
var camlQuery = new SP.CamlQuery();
var query = '<View><Query><Where><Eq><FieldRef Name=\'ServiceOffering\' /><Value Type=\'TaxonomyFieldTypeMulti\'>' + serviceOffering + '</Value></Eq></Where></Query><ViewFields><FieldRef Name=\'Title\'/></ViewFields></View>';
//var query = '<View><Query><Where><Eq><FieldRef Name=\'ServiceOffering\' /><Value Type=\'TaxonomyFieldTypeMulti\'>' + serviceOffering + '</Value></Eq></Where></Query></View>';
//alert("query : " + query);
camlQuery.set_viewXml(query);
this.collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem,'Include(DisplayName,FileRef,DocumentType)');
var listItemEnumerator = collListItem.getEnumerator();
var count = collListItem.get_count();
alert("count: " +count);
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
alert("Value: " + oListItem.get_item('DocumentType').get_label());
}
oListItem.get_item('DocumentType').get_label()
is the place that throws error and the error is
"The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested. when getting data from managed metadata field"
Also note that the column has been created using visual studio.