Working with Discussions List via SharePoint Client Object Model


In this post  will be demonstrated how to perform a common CRUD operations when working with Discussions List via  Client Object Model (JavaScript CSOM) in SharePoint 2010/2013.

Create a Discussion

So, let’s get started with creating a Discussion item. SP.Utilities.Utility.createNewDiscussion method is used for creating a discussion item:

Load all Discussions

Since Discussion Content Type derives from Folder Content Type  we could utilize SP.CamlQuery.createAllFoldersQuery method to construct a query to retrieve all the discussions:

Create a Message

The SP.Utilities.Utility.createNewDiscussionReply method is used to create a Message item (add reply to a discussion item):

Load all Messages

Since message items  are contained within discussion container (Folder) , to identify messages by discussion we will use SPBuiltInFieldId.ParentFolderId field in CAML query:

Import Discussion List

And finally in order to see how to work with Discussions List in action,  let’s discuss one more example.  Suppose we need to import Discussions List content from an external source, let’s say from Stack Exchange. To access Stack Exchange content (Questions and Answers in our case) we will utilize Stack Exchange API:

5 thoughts on “Working with Discussions List via SharePoint Client Object Model

  1. Please elaborate your code, what should be taken as “DiscussionItem” and “Properties” in the example of creating a message. also what is propName?

  2. For the “Create A Discussion” code, I am getting “‘SP.ClientContext.get_current’ is null or not an object” so do you know which JS files need to be linked/included on the page?

  3. Thank you for the post it was helpful! Do you know how I can render the messages within a discussion folder? Once I have all the messages returned in the query, how do I render them similar to Flat.aspx?
    I am currently trying to inject the flat.aspx?IsDlg=1&Folder etc.. ‘all messages for a discussion item’ view into my dashboard using jquery load().

Leave a Reply to dev Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.