0

Suppose there is a discussion list with a discussion item. It has 2 replies. Reply A and Reply B. Reply A is a direct reply to discussion item but Reply B is a reply to Reply A.

With items IDs being 1, 2 and 3 respectively, I get a handle on Reply B, how do I get to know that Reply B was a direct reply to Reply A?

I have tried this in SP management shell:

$web = get-spweb "http://sp2010"
$list = $web.Lists["Team Discussions"]
$ReplyB = $list.GetItemById(3)
Write-Host $ReplyB["ParentFolderId"] #This returns 1, The ID of the discussion item

How does SharePoint manages Replies to Replies in discussion lists internally?

Cheers

3
  • Does this mean there is no actual reply to reply implementation? I mean all replies are actually a reply to single discussion (Parent Discussion Item)? SharePoint just renders item as replies to replies using hidden columns, is there no API method to get to know the reply threaded parent? – Muhammad Usman Jan 30 '15 at 20:46
  • I am not sure about it. – Waqas Sarwar MVP Jan 30 '15 at 21:03
0

Alright, in context of the comments to the question, i have created a pre-liminary logic to check if discussion item is a Reply to Reply.

SharePoint API provides SPUtility.CreateNewDiscussionReply static method to create a reply programmatically. But when it comes to get the parent of a discussion item I couldn't find any API method, neither was I able to find any column which had item ID of (Threading) Parent, though there is a column named ParentReplyId which will always return the parent discussion item ID - confusing as it sounds.

While rendering replies in a threading view, SharePoint makes use of hidden columns one of which is Threading (there are more, can't remember their exact names right now but they have the same values). If you try to peek in the value in this column for a discussion item, it goes as:

#Value in Threading Column for Parent Discussion Item - (ID: 1) - 46 Characters
0x01D20ADFBC6516050BCBEA944043A300C5156D3774F0 

#Value in Threading Column for All Root Discussion Item Replies - (ID: 2) - 56 Characters
0x01D20ADFBC6516050BCBEA944043A300C5156D3774F000000306CE

#Value in Threading Column for a Reply to Reply Item - (ID: 3) - 66 Characters
0x01D20ADFBC6516050BCBEA944043A300C5156D3774F000000306CE000001B069

If you look closely, each reply has a Threading column value appended with 10 chars to the Threading column value of its parent.

So considering the above scenario:

Reply A Threading Column has 00000306CE appended to 0x01D20ADFBC6516050BCBEA944043A300C5156D3774F0 which was the Threading column value for Root Discussion item - (ID: 1).

Here I believe that length of the threading value remains constant i.e. 46 for each Root discussion items and with each reply some 10 randomly characters are appended to the threading column value of its parent's Threading column.

Why the length of all root discussion items Threading value is going to be 46 is answered by the fact how SharePoint structures it. For example

Message (Item) CT ID - Item GUID - Some 10 randomly generated chars
0x01-D20ADFBC6516050BCBEA944043A300C5-156D3774F0
4-32-10 = 46

This might look a little confusing but it will make sense if you think. I have managed to pull a puesdo logic to get the parent item of reply to reply item.

If($ReplyB["Threading"].Length -ge 66)
{
    #Current Item is a Reply to Reply
    #Query for the Reply Parent in discussion list where Threading Column value is current items Threading column value - 10
    #Here you could build a CAML query and find items whose Threading Value is:
    $ReplyB["Threading"].Remove($ReplyB["Threading"].Length - 10)
}

Disclaimer: This code is not tested but i believe it to work. I hope somebody could come and correct me, may be with a better/efficient solution. But for now i think this should work for anybody stuck in the same issue.

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.