SharePoint/PnP-JS-Core

SharePoint Discussion thread

Closed this issue · 5 comments

Thank you for reporting an issue, suggesting an enhancement, or asking a question. We appreciate your feedback - to help the team understand your needs please complete the below template to ensure we have the details to help. Thanks!

Please check out the Developer Guide to see if your question is already addressed there. This will help us ensure our documentation covers the most frequent questions.

Category

[ ] Enhancement

[ ] Bug

[X] Question

Version

Please specify what version of the library you are using: [ latest ]

Anyone knows how to query for replies for one SharePoint Discussion thread? seen somewhere that you need to Post a CAML to the folder. Is there a PNP JS Core example for that?
Thanks in advance

Hey @Ofer-Gal,

A discussion board, if to oversimplify, is nothing more than a list with discussion content type derived from a folder's one and messages, which are items in folders.

Considering this, any approaches available in REST for list with folders will work. For instance:

(async () => {

const listUri = `${_spPageContextInfo.webServerRelativeUrl}/Lists/DiscussionBoard`;
const discussionList = pnp.sp.web.getList(listUri);

const discussions = await discussionList.items
  .select('*,FileRef') // FileRef is a discussion folder path
  .filter(`startswith(ContentTypeId, '0x0120')`).get();

console.log(`Discussion: ${discussions[0].Title}`);
console.log(`Discussion folder: ${discussions[0].FileRef}`);

// Getting messages by folder filtering
const messages = await discussionList.items
  .filter(`FileDirRef eq '${discussions[0].FileRef}'`).get();

console.log(messages);

console.log(`Discussion: ${discussions[1].Title}`);
console.log(`Discussion folder: ${discussions[1].FileRef}`);

// Getting messages with renderListDataAsStream method and folder param
const messages2 = await discussionList.renderListDataAsStream({
  ViewXml: '<view></view>', // Dont miss further conf
  FolderServerRelativeUrl: discussions[1].FileRef
});

console.log(messages2);

})();

Hope this will help.

thx @koltyakov that relay helped.
Having to support IE10 I could not use the great ES6 syntax :-( but was able to translate to simple jQuery.
the reply filter: "filter(FileDirRef eq '${discussions[0].FileRef}')" always returened empty []
But the discussionList.renderListDataAsStream had a Row object with all the replies.
I am only straggling with "ParentItemID" and "Editor.title" that is showing when I get all the list items but not in the results of renderListDataAsStream
I changed the view to:"ViewXml: "<view><ViewFields><FieldRef Name='ParentItemID'/></ViewFields></view>" but it did not help.
Is there another way to tell it which fields to render? and expand the Editor?

I could not use the great ES6 syntax

Sorry to hear it. Can't even recall the last time I needed to write raw ES5 ever. It's usually ES2017 or TypeScript and transpilation to ES5 involved.

FileDirRef eq '${discussions[0].FileRef}' corresponds to the following ES5:

"FileDirRef eq '" + discussions[0].FileRef} + "'"

Please check, you should be receiving discussion messages with usual OData $select, $expand capabilities.

With renderListDataAsStream I got all the fields you mentioned with an empty <View></View>:

image

image

Nice! Going to close the issue.