Closed Ofer-Gal closed 6 years ago
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>
:
Turns out the ParentItemID was always null because the list was a copy of a list from other site collection and the ParentItemID is not populated. Working on a "Legit" discussion showed values.
So my bad :-) Thank you much.
On Tue, Apr 24, 2018 at 3:41 AM, Andrew Koltyakov notifications@github.com wrote:
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
: [image: image] https://user-images.githubusercontent.com/7816483/39176004-5eac4628-47b4-11e8-87fe-f547bdab9c4e.png
[image: image] https://user-images.githubusercontent.com/7816483/39176048-77dd2d92-47b4-11e8-97e2-d4db8490f302.png
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SharePoint/PnP-JS-Core/issues/787#issuecomment-383852225, or mute the thread https://github.com/notifications/unsubscribe-auth/AE0h03kkhCKirRGCqVuKjSZMmkYKVJRsks5truVRgaJpZM4TerTR .
-- Thank you Ofer Gal
לפני הפצת שרשרת, נא מחקו את שמי וכתובתי מהדוא"ל, כדי שהפרטים לא יגיעו לחורשי מרעין בישין ברחבי האינטרנט
Nice! Going to close the issue.
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