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:
Found a useful post about #SharePoint Web Services #SP2010 #in
In my travels of playing with the SharePoint Web Services, I found the following post useful.
Although it is based on WSS 3.0 / MOSS 2007. Much of it is still relevant for SharePoint 2010.
http://bhavtosh.wordpress.com/2009/10/05/sharepoint-2007-web-services/
Recommended Podcast
Top Posts
- Office 365 Products Visio Stencil & Icons available (updated for 2019) #o365 #visio
- Excel formulas not auto calculating but F9 still works #in
- Programmatically Disable Event Firing on List Item Update in SharePoint 2010
- Automating SharePoint 2013 Usage Reports
- Take control of your log files
- SharePoint 2013 User Profile Service Application Publishing
- Formatting #ProjectServer PDP using #CSS and #JavaScript
- Unique alphanumeric list ID's via SPD Workflow and Calculated Columns #SharePoint #SP2010 #in
- How do I: Add new values to a drop-down list from the new item form
- Group has Full Control but you cannot add a user to the group? #SharePoint
Archives
Tags
Blog Stats
- 607,837 hits