Hi All,
In one of our news listing web part we have requirement to show the comments count for given news. On news pages we are using the NoteBoard web part for commenting purpose.
For news listing we are using OOB Content by Search (CBS) web part and in front of news title we need to show the comment count.
Since we are using OOB web part we don’t have an option of code where we can create SocialCommentManager class and call GetCount(Uri) method. The other option is to use the SocialDataService (SocialDataService.asmx) and call this from the display template of CBS web part. This solution is also compatible with Office 365.
Following is the sample script:
- function ReturnCommentsCount(url) {
- var dataXML = GenerateDataXML([url]);
- $.ajax({
- url: "/_vti_bin/SocialDataService.asmx?op=CountCommentsOnUrl",
- data: dataXML,
- type: "POST",
- async: true,
- complete: processResult,
- contentType: "text/xml; charset=utf-8",
- dataType: "xml"
- })
- //Following function generates the require soap XML
- function GenerateDataXML (url) {
- var soapXml = "<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/\">" +
- "<soap:Body>" +
- "<CountCommentsOnUrl xmlns=\"http://microsoft.com/webservices/SharePointPortalServer/SocialDataService\">" +
- " <url>" + url + "</url>" +
- "</CountCommentsOnUrl>" +
- "</soap:Body>" +
- "</soap:Envelope>"
- return soapXml;
- }
- function processResult(content, txtFunc, xhr) {
- // Here we get the actual comment count
- //We can set this to any span element
- var commentsCount = $(content.responseText).find('CountCommentsOnUrlResult').text();
- }
- $("#commentcount”).text(commentsCount);
Complete processResult method will be like:
- function processResult(content, txtFunc, xhr) {
- // Here we get the actual comment count
- //We can set this to any span element
- var commentsCount = $(content.responseText).find('CountCommentsOnUrlResult').text();
- $("#commentcount”).text(commentsCount);
- }
Enjoy reading
Feel free if any comment / question.

Gowtham RajamanickamPosted Aug 7, 2015, 5:56 AM
i have subsite for news article .like https://thetest.spdev.com/news. in this subsite i have many pages.user can able to post the comments in all pages under the subsite.is it possible to get the all comments from subsite.
Prasham SabadraPosted Sep 22, 2014, 1:16 AM
Thanks!
Saineshwar BageriPosted Sep 20, 2014, 11:52 PM
Nice article sir