4

If you use SharePoint 2013 enterprise search and you find a comment on a blog post in your results it will be given the Default Display Template (Item_Default.js) by default.

It gives 3 values: Title, part of the text, URL

Screenshot with default template showing blog post comment

When you click on it, SharePoint uses ViewComment.aspx to show the item. Here you get the title, the full text and information about the creator. Screenshot showing item in ViewComment.aspx

On both places you have no chance to get to the blog post to which the comment is related. My approach was to create a custom display template for this. Sadly the item in SharePoint search has 62 attributes with values but there is no attribute with id or url of parent blog post.

This are the attributes for this comment on a blog post SharePoint knows by default:

  1. Rank [object Number]
  2. DocId [object Number]
  3. Author [object String]
  4. AuthorOWSUSER [object String]
  5. BodyOWSMTXT [object String]
  6. ContentSource [object String]
  7. ContentType [object String]
  8. ContentTypeId [object String]
  9. Created [object Date]
  10. CreatedOWSDATE [object String]
  11. DefaultEncodingURL [object String]
  12. DetectedLanguage [object String]
  13. DetectedLanguageRanking [object Number]
  14. DiscoveredTime [object Date]
  15. DiscussionPost [object String]
  16. DisplayAuthor [object String]
  17. DocumentSignature [object String]
  18. EditorOWSUSER [object String]
  19. FallbackLanguage [object String]
  20. FileExtension [object String]
  21. Filename [object String]
  22. IndexDocId [object Number]
  23. InternalFileType [object Number]
  24. IsContainer [object Boolean]
  25. IsDocument [object Boolean]
  26. IsListItem [object Boolean]
  27. LastModifiedTime [object Date]
  28. ListID [object String]
  29. ListItemID [object String]
  30. MetadataAuthor [object String]
  31. ModifiedBy [object String]
  32. ModifiedOWSDATE [object String]
  33. NonDocument [object Boolean]
  34. OriginalPath [object String]
  35. ParentLink [object String]
  36. Path [object String]
  37. People [object String]
  38. ReplyCount [object Number]
  39. SPSiteURL [object String]
  40. SPVersion [object Number]
  41. SecurityId [object String]
  42. SiteID [object String]
  43. SitePath [object String]
  44. SiteTitle [object String]
  45. Size [object Number]
  46. Title [object String]
  47. UIVersionStringOWSTEXT [object String]
  48. UniqueID [object String]
  49. UrlDepth [object Number]
  50. WebId [object String]
  51. ZCHNAENDBODY [object String]
  52. contentclass [object String]
  53. language [object String]
  54. languages [object String]
  55. owsID [object Number]
  56. ResultTypeIdList [object String]
  57. PartitionId [object Object]
  58. UrlZone [object Number]
  59. AAMEnabledManagedProperties [object String]
  60. ResultTypeId [object Number]
  61. RenderTemplateId [object String]
  62. piSearchResultId [object String]

Has anyone a hint or approach to give my users a way to get from the search result of a comment to the realted blog post?

Thanks in advance!

Disclaimer: I used StackExchange search and Google intense before posting this. Only related item I found was Find the blog post associated with a comment programmatically which did not give me the possibiltity to resolve my issue.

1
  • Is it the ParentId or ParentLink? Commented May 13, 2017 at 11:27

2 Answers 2

4

Comments list stores PostTitle which in turn contains both ID and Title for the Post. In the ViewComments.aspx page, you can use REST api to create a link to the related Post.

var listname = 'Comments';
JSRequest.EnsureSetup(); // or use other function to retrieve param
var id = JSRequest.QueryString["ID"];

//REST call
var call = $.ajax({
    url: _spPageContextInfo.webAbsoluteUrl
    + "/_api/web/lists/getbytitle('" + listname + "')/items(" + id + ")"
    + "?$select=PostTitle/Id,PostTitle/Title"
    + "&$expand=PostTitle",
    type: "GET",
    dataType: "json",
    headers: {
        Accept: "application/json;odata=verbose"
    }
});

call.done(function (data) {
    //window.console && console.log(data);
    var response = data.d;

    var subMenuAnchor = $('<a/>', {
        href: _spPageContextInfo.webAbsoluteUrl + "/Lists/Posts/Post.aspx?ID=" + response.PostTitle.Id,
        html: response.PostTitle.Title
    });

    var relatedItemHeader = $('<h3/>', {
        html: subMenuAnchor
    });
    //Find an element on the ViewComments page to append the result
    relatedItemHeader.appendTo(document.getElementById('MSOZoneCell_WebPartWPQ1'));

});

call.fail(function (jqXHR, textStatus, errorThrown) {
    alert("Error: " + jqXHR.responseText);
});
3

By default there is no managed property for comments' parent PostId and PostTitle, thus they're not retrievable via search.

You have to manually create a managed property "PostId" and map the crawled property "ows_PostID". Start a full crawl. Now the "PostId" property is included with every blog comment you retrieve via search. (The same goes for "ows_PostTitle" in case you need it.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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