sharepointsharepoint-onlinespfxpnp-js

How do you remove comments from a specific item of a Sharepoint list?


The delete () function of the IComments interface (PnP) does not delete the comment I select through the index, how can I use it? (@pnp/sp/comments)

in this way I get the comments of the item to which I will pass the index, but once I try to use the delete it is not read.


Solution

  • Use the clear method exposed by IComments. The clear method would delete all comments on the item returned.

      const item = sp.web.lists.getByTitle('Title').items.getById(1);
      await item.comments.clear();
    

    Or you could use the snippet below which will delete the comment with the specified id.

      const commentId = 2000;
      await item.comments.getById(commentId).delete();