5

I am able to get Questions from Discussion board using REST API.

Now I want to get its replies for particular Question using REST API.

I didn’t found any hint or example to get Replies using REST.

I have Some Additional Fields Columns in Discussion Board. Like some Text and some Lookup .

When I am give reply then its just give add data only in body part . but I want to Add all Items when user reply.

Second things is when I am Giving Reply from flat view it fill parentId but not other fields.

And When i am add new Item in Reply view its provide view to add all column field to fill but not Adding ParentID

Any help very Appreciated.

1 Answer 1

3

You wrote you have already the particular question you need the replies for. Then you should now its ID as well. Using that ID you can filter the items for the replies for the particular question via REST (assuming the ID is 234):

http://YourServer/YourSite/_api/Web/Lists/GetByTitle('TitleOfYourDiscussionBoard')/Items?$filter=ParentItemID eq 234

Note, that this query returns only the direct responses to the question, but not the replies for the responses.

To understand the other approach (returning any responses that belong to a question, independently from the position in the structure), you should first know, that dicsussion board threads are organized as a folder structure. The threads (the questions) are folders, and the answers for the questions are items within the corresponding folder.

You can get the folder objects for your question as:

http://YourServer/YourSite/_api/Web/Lists/GetByTitle('TitleOfYourDiscussionBoard')/Items(234)/Folder

See the ServerRelativeUrl property of the returned item. Assume it is '/YourSite/Lists/DiscussionBoard/Question234'.

Next send a POST (not a GET!) request to the server with the URL below to get all items within the folder (that means, all answers for the particular question):

/_api/web/Lists/GetByTitle('DiscussionBoard')/GetItems(query=@v1)?@v1={"ViewXml":"<View Scope='Recursive'><Query><Where><Eq><FieldRef Name='FileDirRef' /><Value Type='Text'>/YourSite/Lists/DiscussionBoard/Question234</Value></Eq></Where></Query></View>"}

Don't forget to escape the apostrophes in this text when using it in code as string!

var request = "/_api/web/Lists/GetByTitle('DiscussionBoard')/GetItems(query=@v1)?@v1={\"ViewXml\":\"<View Scope='Recursive'><Query><Where><Eq><FieldRef Name='FileDirRef' /><Value Type='Text'>/YourSite/Lists/DiscussionBoard/Question234</Value></Eq></Where></Query></View>\"}";

Alternatively (as long as you are working with JavaScript and not C#) you can build up a JavaScript object and stringify it via JSON.stringify.:

var query = {
    ViewXml: "<View Scope='Recursive'><Query><Where><Eq><FieldRef Name='FileDirRef' /><Value Type='Text'>/YourSite/Lists/DiscussionBoard/Question234</Value></Eq></Where></Query></View>"
};

var request = "/_api/web/Lists/GetByTitle('DiscussionBoard')/GetItems(query=@v1)?@v1=" + JSON.stringify(query);
9
  • but what i am facing problem is i have some additional field columns. so when i give reply from flat view its just put in body column not other fields. Aug 10, 2016 at 6:50
  • and if i am dding reply using new item its give option to add all fileds but its not add parent ID Aug 10, 2016 at 6:50
  • OK, now I understand your problem. Let's see if I can find something useful for you...
    – pholpar
    Aug 10, 2016 at 7:01
  • I know using this i can achieve this but i didnt get parent ID when i am adding using new items in reply view Aug 10, 2016 at 7:01
  • Sorry, I can't reproduce your problem. The answers are created with a ParentID, either from the Flat view or the Threaded view. What do you mean on "reply view"? Could you write the name of its aspx page, please (like Flat.aspx for the Flat view)? If you create a new item, it will be created as a new discussion, of course without any parent and ParentID.
    – pholpar
    Aug 10, 2016 at 7:33

Your Answer

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

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