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.