Deleting a comment in a modern SharePoint page
-
20-01-2021 - |
Question
Is it possible to delete a single comment from the comment section at the bottom of the a SharePoint modern page?
Any help with this would be much appreciated!
La solution
We can use REST API to retrieve comments, and manage comments.
To delete a specific comment from a modern page, make a Delete request to:
https://technet.sharepoint.com/sites/<site>/_api/web/lists(<list GUID>')/GetItemById(<page item id>)/Comments(<comment id>)
Reference:
Working with the Page Comments REST API
A script demo of deleting a comment from a modern page:
<script src="https://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
<script>
ExecuteOrDelayUntilScriptLoaded(DeleteComment, "sp.js");
function DeleteComment() {
var siteURL = _spPageContextInfo.webAbsoluteUrl;
console.log("from top nav - " + siteURL);
var apiPath = siteURL + "/_api/web/lists('F0D56E41-B532-4F0D-A5B2-000FDE46B86F')/GetItemById(26)/Comments(1)";
$.ajax({
url: apiPath,
type: "DELETE",
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"If-Match": "*"
},
async: false,
success: function(data) {
alert("The comment Deleted successfully");
},
eror: function(data) {
console.log("An error occurred. Please try again.");
}
});
}
</script>
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange