2

I have a Discussion Board with a series of replies. Each 'Message' (Reply) Content Type has an 'Answer' dropdown with the values 'YES/NO' (NO being default)

I have created a hyperlink on the property bar (where the 'Reply' and 'View Properties' links are) called 'Mark as Answer'.

Im basically wanting to execute some Javascript when this link is clicked to update the Reply (Message Content Type) 'Answer' dropdown to be' YES'. Ive looked online and it is apparent the Discussion Boards arent like normal lists and you cant just use normal SP List update commands in code. I have found code to programatically Create a Reply but I cannot find anything to guide me in the direction of Updating a reply.

Im guessing I need to pull the Item ID from the reply and then update the field based on this ID. Can anyone point me in the correct direction code wise?

Thanks

1

Since a reply in Discussion Board is represented as List Item you could utilize a common update operation as demonstrated below:

var ctx = SP.ClientContext.get_current(); 
var list = ctx.get_web().get_lists().getByTitle('Discussion Board');
var messageItem = list.getItemById(listItemId); //get message item by its Id
messageItem.set_item('Body','Welcome to SharePoint 2013!');
messageItem.update();

messageItem.update();
ctx.executeQueryAsync(
   function(){
        console.log('Reply has been updated');
    },
    function(sender,args){
         console.log('Error occurred while upading a reply:' + args.get_message());
    }
);

References

How to: Complete basic operations using JavaScript library code in SharePoint 2013

  • 1
    One thing to keep in mind is that the Discussion board stores things in a folder structure, that might increase the complexity of the solution – Choggo Nov 9 '14 at 21:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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