You are on page 1of 4

<div id="filter"></div> <!-- Change this to your settings --> <script type="text/javascript" src="http://home-d.grintranet.com/Training/Shared %20Documents/jquery.SPServices-2013.02a.

js" language="javascript"></script> <script type="text/javascript" src="http://home-d.grintranet.com/Training/Shared %20Documents/jquery-1.9.0.js" language="javascript"></script> <script> var TaxTerms = { termId: "", termName: "", child: null } var TaxConfiguration = { SspId: "", GroupId: "", TermSetId: "", Configuration: "", ParseConfiguration: function () { xmlDoc = $.parseXML(this.Configuration); xml = $(xmlDoc); var properties = xml.find("Property"); for (i = 0; i < properties.length; i++) { propertyName = properties[i].firstChild.textContent == undefined ? properties[i].firstChild.text : properties[i].firstChild.textContent; propertyValue = properties[i].lastChild.textContent == undefined ? properties[i].lastChild.text : properties[i].lastChild.textContent; if (propertyName == propertyValue) { propertyValue = ""; } switch (propertyName) { case "SspId": this.SspId = propertyValue; break; case "GroupId": this.GroupId = propertyValue; break; case "TermSetId": this.TermSetId = propertyValue; break; } } } } function GetTermsRecursive(sspId, termSetId){

var terms = new Array(); var returnValue; $().SPServices({ operation: "GetChildTermsInTermSet", sspId: sspId, termSetId: termSetId, lcid: 1033, completefunc: GetData }); } function GetChildTermsRecursive(sspId, termSetId, roottermId){ var terms = new Array(); $().SPServices({ operation: "GetChildTermsInTerm", sspId: sspId, termId: roottermId, termSetId: termSetId, lcid: 1033, completefunc: GetData }); return terms; } function GetData(xData, Status) { if(Status == "success") { terms = new Array(); xmlData = xData; // Fix for different XML parsing in IE and Chrome termsContent = $.parseXML(xmlData.responseText).firstChild.textConte nt == undefined ? $.parseXML(xmlData.responseT ext).text : $.parseXML(xmlData.responseT ext).firstChild.textContent; termsXML = $.parseXML(termsContent); $termsXML = $(termsXML); console.log($termsXML); childTerms = $termsXML.find("T"); parentTermId = null; filterOutput = "<ul>"; for(i = 0; i < childTerms.length; i++) { termName = $(childTerms[i]).find("TL"); hasChildTermsXml = $(childTerms[i]).find("TM");

// request if child terms are avaliable hasChildTerms = $(hasChildTermsXml).attr("a69"); var tsTerm = new Object(); // Requesting actual term id tsTerm.termId = $(childTerms[i]).attr("a9"); // Requesting term name tsTerm.termName = termName.attr("a32"); // Setting Parent Term ID parentTermId = $(hasChildTermsXml).attr("a25"); filterOutput += "<li id='"+tsTerm.termId+"'>"+tsTerm.ter mName; // If child terms are avaliable query child terms if(hasChildTerms != undefined && hasChildTerms == "true" ){ // Request child Terms tsTerm.child = GetChildTermsRecursive(taxconfig. SspId, taxconfig.TermSetId, tsTerm.termId); tsTerm.hasChildTerms = true; } else { tsTerm.child = null; tsTerm.hasChildTerms = false; } filterOutput += "</li>"; terms[i] = tsTerm; } filterOutput += "</ul>"; // If parent element is specified query for parent element if(parentTermId != undefined || parentTermId != null){ $("#"+parentTermId).append(filterOutput); } else { currentFilter = $("#filter").html(); $("#filter").html(currentFilter+filterOutput); } return terms; } } var var var var fieldCollection; locationField = null; termSetTerms = Array(); taxconfig = TaxConfiguration;

ExecuteOrDelayUntilScriptLoaded(getLocation, "sp.js"); function getLocation() { var clientContext = SP.ClientContext.get_current(); if (clientContext != undefined && clientContext != null) { var webSite = clientContext.get_site().get_rootWeb(); // Select 'Location' Field fieldCollection = webSite.get_fields(); this.locationField = fieldCollection.getByInternalNameOrTitle("Location" ); // Load Context clientContext.load(this.fieldCollection); clientContext.load(this.locationField); clientContext.executeQueryAsync( Function.createDelegate(this, this.OnLoadSuccess), Function.createDelegate(this, this.OnLoadFailed) ); } } function OnLoadSuccess(sender, args) { var fieldInfo = ''; var fieldschema = locationField.get_schemaXml(); taxconfig.Configuration = fieldschema; taxconfig.ParseConfiguration(); try{ var taxsspId = taxconfig.SspId; var termSetId = taxconfig.TermSetId; GetTermsRecursive(taxconfig.SspId, taxconfig.TermSetId); } catch (e) { console.log(e); } } function OnLoadFailed(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace() ); } </script>