Archive
Using jQuery to return the Managed Metadata Term GUID #SP2010 #SharePoint #in
For a completely different client who is using SharePoint 2010 for their company intranet we needed to implemented a UI web part which allowed end users to click on keywords which would then pre-filter search.
Keywords were entered in using the new Managed Metadata feature of SharePoint 2010.
However, during development we found that SharePoint Search for Managed Metadata does not use just the standard ?k= query string parameter to run the search query.
A new query string parameter is available especially for Managed Metadata:
- &r=
And the expected format is similar to the following:
- “ManagedMetadataTerm:TermGUID”
NB: I will probably explain the above in more detail in a later post
Anyway, when querying the lists.asmx web service and returning managed metadata columns, only the values are returned, not the GUID’s which poses us a problem for restricting search.
So after some research I came up with the following jQuery function calling the taxonomyClientService.asmx web service introduced in SharePoint 2010.
It’s is pretty basic at the moment but suits the requirement for my client in their setup:
Code Example:
1 <script type="text/javascript"> 2 $(document).ready(function() { 3 getTermsByLabel("Project Server"); //pass your variable in here; 4 }); 5 6 function getTermsByLabel(termString) { 7 var soapEnv = 8 "<?xml version='1.0' encoding='utf-8'?> \ 9 <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \ 10 <soap:Body> \ 11 <GetTermsByLabel xmlns='http://schemas.microsoft.com/sharepoint/taxonomy/soap/'>\ 12 <label>" + termString + "</label>\ 13 <lcid>1033</lcid>\ 14 <matchOption>ExactMatch</matchOption>\ 15 <resultCollectionSize>100</resultCollectionSize>\ 16 <addIfNotFound>0</addIfNotFound>\ 17 </GetTermsByLabel>\ 18 </soap:Body> \ 19 </soap:Envelope>"; 20 //alert(soapEnv); 21 $.ajax({ 22 url: "/_vti_bin/taxonomyclientservice.asmx", 23 type: "POST", 24 dataType: "xml", 25 data: soapEnv, 26 complete: processResult, 27 contentType: "text/xml; charset=\"utf-8\"" 28 }); 29 } 30 31 function processResult(xData, status) { 32 //alert(status); 33 //alert(xData.responseText); 34 35 $(xData.responseXML).find("GetTermsByLabelResult").each(function() { 36 37 var outputValue = $(this).text(); 38 var a9Array = outputValue.split("a9="); 39 var a21Array = a9Array[1].split("a21="); 40 var termGUID = a21Array[0].replace(/"/g, ""); 41 termGUID = white_space(termGUID); 42 alert("-=" + termGUID + "=-"); 43 44 }); 45 46 } 47 48 function white_space(stringValue) { 49 stringValue = (stringValue).replace(/^\s*|\s*$/g,''); 50 return stringValue; 51 } 52 53 </script> 54
Links I found useful during my research:
- TaxonomyClientService.asmx MSDN Reference:
- GetTermsByLabel MSDN Reference:
- Blog Post 1 – .NET Examples:
- Blog Post 2 – .NET Examples + Analysis of the XML output:
Tags
Top Posts
- Uploading an Existing Local Git Repository to BitBucket.
- Win7 SharePoint 2016 SSL and Office 2013
- So, you want to delete users with the Azure AD Graph API? Good luck with that!
- Updating User Profile Properties via PowerShell (PictureURL)–SharePoint 2010 #in #SP2010
- Excel formulas not auto calculating but F9 still works #in
- Take control of your log files
- #ProjectOnline #PowerBI Report – Include #HTML formatting #PPM #PMOT #PowerQuery #OData #REST Part 1
- Updating resource rates
- Project Server - "An unknown error has occurred"
- #O365 #SharePoint Online–Information Rights Management #IRM–what works, what doesn’t in a business context-Part 2
Archives
Blog Stats
- 604,215 hits