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:
Leave a Reply Cancel reply
Recommended Podcast
Top Posts
- Office 365 Products Visio Stencil & Icons available (updated for 2019) #o365 #visio
- #ProjectOnline Project Ideas list view with Project GUID #Office365 #SharePoint #JavaScript #jQuery
- Slipstream #Project Professional 2010 updates #MSProject #PS2010 #PS2007 #ProjectServer #MSOffice
- Embedding PDF files with the Content Editor Web Part #SP2010 #SP2013 #MSProject
- Formatting #ProjectServer PDP using #CSS and #JavaScript
- So, you want to delete users with the Azure AD Graph API? Good luck with that!
Archives
Tags
.NET Android Azure Business Intelligence C# Calculated Column Certification Chris Clements Client Object Model CodePlex conference CU Development EPM Excel Form Services 2010 François Souyri InfoPath 2010 Information Rights Management iOS iPad iPhone IRM ISCLondon JavaScript JQuery Microsoft Word Mobile Application MOSS 2007 Office 365 Office 2010 Other Performance PowerBI PowerShell Presentation Project Project 2010 Project 2013 Project Conference 2012 Project Management Project Managment Project Online Project Server Project Server 2007 Project Server 2010 Project Server 2013 PS2007 PS2010 Rights Management Server RMS Search SharePoint SharePoint 2010 SharePoint 2013 SharePoint 2016 SharePoint Designer 2010 SharePoint Online SharePoint Saturday UK SP.ClientContext.get_current() SP2010 SP2016 Speaking Engagements SPF 2010 sql server reporting services Supported File Types TechEd Europe 2012 Technical Preview visio Visual Studio 2010 Visual Web Part Web Part Windows 7 Workflow WSS 3.0Blog Stats
- 621,689 hits
Brilliant. This exactly what I needed, Giles… thanks.
Hey Giles, you run into a access denied with this solution? I have been trying to incorporate this call into an Office App. I would think it would impersonate the user opening the word app but that does not appear to be the case…