Thursday, December 30, 2010

SharePoint 2010 how to get Social Comments Count using jQuery and webservice

Hi Everyone.This is my first blog post and I wanted to share some of my tough scenarios where I spent more time to find solutions. One of issue I spent more time was finding the number of comments for a page without customization (i.e., without doing managed code). Then I found some scripts which will fetch SharePoint 2010 social comments using webservice and jquery script. I hope it might help for some developers.

<script src="/sites/dev001Portal/styles/JS/jquery.SPServices-0.5.8P1.js" type="text/javascript"></script>
<script src="/sites/dev001Portal/styles/JS/jquery.min.js" type="text/javascript"></script>                                                                                            
 <script type='text/javascript'>
var strUrl = location.href;


function CallCountMethod(strUrl) {
    var CountMethod;
    var Counter;
        CountMethod = '/_vti_bin/SocialDataService.asmx?op=CountCommentsOnUrl';
            var Counter = "<soap:Envelope xmlns:xsi='' xmlns:xsd='' \
                    xmlns:soap=''> \
                          <soap:Body>    \
                               <CountCommentsOnUrl xmlns=''> \
                                <url>" + strUrl + "</url> \
                            </CountCommentsOnUrl> \
                        </soap:Body> \

        type: "POST",
        async: true,
        url: CountMethod,
        data: Counter,
        contentType: "text/xml; charset=utf-8",
        dataType: "xml",
        success: function(content, txtFunc, XMLHttpRequest) {
                    GetCommentsCount(content, txtFunc, XMLHttpRequest, strUrl);

function GetCommentsCount(content, txtFunc, XMLHttpRequest, strUrl) {
     var count = 0;
     count = $('CountCommentsOnUrlResponse', data).find('CountCommentsOnUrlResult').text();
     document.getElementById('showCount').innerHTML = comb;

// Executing the above script will show the count into the below div tag.
<div id="showCount"></div>

=//\\Enjoy Programming//\\=


  1. Some Modifications in the above code got it worked

    GetCommentsCount(data, txtFunc, XMLHttpRequest, strUrl)

  2. document.getElementById('showCount').innerHTML = count;