2

I am using discussion board as a comment board for my Assets library in SharePoint 2013

I am very well able to retrieve the topic and replies from the discussion board.

What I want is to post a reply to these topics using JSOM.

There is an AddDiscussionBoardItem method in C#, is there a JSOM alternative to this?

1 Answer 1

2

How to post a reply in Discussion Board using SharePoint JSOM

Use SP.Utilities.Utility.createNewDiscussionReply(Context, parent) Method to post a reply to a discussion item:

function createMessage(discussionItem,properties,OnItemAdded,OnItemError)
{
    var context = new SP.ClientContext.get_current();
    var messageItem = SP.Utilities.Utility.createNewDiscussionReply(context, discussionItem);
    for(var propName in properties) {
       messageItem.set_item(propName, properties[propName]) 
    }
    messageItem.update();
    context.executeQueryAsync(
        function() {
          OnItemAdded(messageItem);           
        },
        OnItemError
    );
}

Example

var ctx = SP.ClientContext.get_current(); 
var list = ctx.get_web().get_lists().getByTitle('Discussion Board');
var discussionItem = list.getItemById(1);   

var messageProperties = {'Body': 'SharePoint 2013 is used in our company'}; 
createMessage(discussionItem,messageProperties,
    function(){
        console.log('Reply has been post successfully');
    },
    function(sender,args){
         console.log('Error occurred while posting a reply:' + args.get_message());
    }
);

For a more details please follow this post.

Your Answer

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

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