1

I'm at my wits end with this problem. basically, what I'm trying to do is activate comments and ratings on my pages (the pages have managed navigation.

I've added comments using the SocialCommentControl control on my page and it's working fine, except i cant get the right comment count for that page.

I later found out that on the social db, the url that gets associated with the comment is not the friendly one but a rather long one having termId, termstoreId and termSetId

So, to count the comments I am doing

function commentCount(managedContextInfo, urlContextInfo, itemId){
        var articleUrl=urlContextInfo.siteAbsoluteUrl.replace(urlContextInfo.webServerRelativeUrl,'')+urlContextInfo.serverRequestPath;
        articleUrl+="?TermStoreId="+managedContextInfo.termStoreId;
        articleUrl+="&TermSetId="+managedContextInfo.termSetId;
        articleUrl+="&TermId="+managedContextInfo.termId;
        articleUrl+="&UrlSuffix="+itemId;

        var soapEnv =
            "<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/'> \n" +
            "<soap:Body>\n"+
                    "<CountCommentsOnUrl xmlns='http://microsoft.com/webservices/SharePointPortalServer/SocialDataService'> \n"+
                        "<url>" + articleUrl + "</url>\n"+
                    "</CountCommentsOnUrl>\n"+
                "</soap:Body>\n"+
            "</soap:Envelope>";

        jQuery.ajax({
            headers: {
                "Accept": "text/xml",
                "X-RequestDigest": $("#__REQUESTDIGEST").val()
            },
            processData: false,
            url: "/_vti_bin/SocialDataService.asmx?op=CountCommentsOnUrl",
            type: "POST",
            dataType: "xml",
            data: soapEnv,
            contentType: "text/xml; charset=\"utf-8\"",
            error: function(xhr, ajaxOptions, thrownError) {
                console.log("Error: " + xhr.status + " " + thrownError + "\nResponseText: " + xhr.responseText);
            },
            success: function (data, status, xhr) {
                console.log(data);               
            }
        });
}

I am calling this function with _spFriendlyUrlPageContextInfo, _spPageContextInfo and ctx["CurrentItem"]["ListItemID"].

As is, this code returns a Error: 400 Bad Request

By trial and error i found out that (don't know if its the sole reason) the character "&" present in the variable articleUrl is causing some form of xml formatting error. If I replace it with "%26", use encodeURI(articleUrl) or encodeURIComponent(articleUrl) at best I get a valid response but the count is always zero.

Now, I am constructing the url this way because I know its the way its stored on the database SharePoint_UserProfileSocialDB. The way I see it, the problem is that I'm encoding it one way and the webservice SocialDataService is decoding it in some other way.

Can anyone shed some light?

1

as it turned out, i had to encode the ampersand character as & amp ;.

  • So did you get it figured out? – MonkeyWrench Oct 27 '16 at 22:31
  • 1
    better use encodeURIComponent() – domsen123 Oct 31 '16 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.