Skip to content

Instantly share code, notes, and snippets.

@maxali
Created June 20, 2017 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxali/8fc6a5a20cbc7cf787a62ff956d411ac to your computer and use it in GitHub Desktop.
Save maxali/8fc6a5a20cbc7cf787a62ff956d411ac to your computer and use it in GitHub Desktop.
/*
Rest query example:
var url = _spPageContextInfo.siteServerRelativeUrl + "/_api/web/lists/getbytitle('ListName')/items?";
url = url + "&$expand=TaxCatchAll,FHI_Responsible";
url = url + "&$select=*,TaxCatchAll/Term,TaxCatchAll/IdForTerm,TaxCatchAll/Term1033,TaxCatchAll/Term1044";
*/
// usage
// getTaxonomyValue(listItem, field);
/**
* extracts Taxonomy field value from TaxCatchAll field.
* listItem includes $select=TaxCatchAll/Term,TaxCatchAll/IdForTerm,TaxCatchAll/Term1033,TaxCatchAll/Term1044
* @returns {String}
* @param {ActivityList.Value} listItem SP ListItem in json;odata=nometadata format
* @param {String} field SP Field internal name
*
* @memberOf ActivityItems
*/
function getTaxonomyValue(listItem, field) {
if (!listItem[field]) return;
var taxField: TaxField = listItem[field];
var taxCatchAll = listItem.TaxCatchAll;
var taxFieldInfo = taxCatchAll.find(tax => tax.IdForTerm === taxField.TermGuid);
return taxFieldInfo['Term' + _spPageContextInfo.currentLanguage] || taxFieldInfo['Term']
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment