Read Comments in Tasks via JavaScript
-
08-02-2021 - |
Frage
I am trying to read the comments of a task list in SharePoint 2016 by using JavaScript.
Right now I get the latest comment using:
var comment = oListItem.get_item('Comments');
But how can I read all comments and how I can get more information like the person who wrote this comment?
Lösung
you can use the below code to get the version history of Comments field,
function getFieldHistory (itemId, fieldName) { //Get each item version history with comment using SPServices
var HTML='';
var ItemID ="", AdditionalComments= "";
var i = 1;
$().SPServices({
operation: "GetVersionCollection",
strlistID: "{A4538568-2FC1-44E2-BAFC-D5DB2C64FF0D}",
strlistItemID: itemId,
strFieldName: fieldName,
completefunc: function (xData, Status) {
var xmlDoc = $.parseXML(xData.responseText);
$xml = $(xmlDoc);
var values = $xml.find("Versions > Version").each(function () {
AdditionalComments = $(this).attr(fieldName);
var Editor= $(this).attr("Editor");
Editor=Editor.substring(0,Editor.indexOf(','));
Editor=Editor.split('#')[1];
var temp= $(this).attr("Modified");
tempModified=temp.split('T')[0];
tempModified= new Date(temp);
Modified=(tempModified.getMonth() + 1) + '/' + tempModified.getDate() + '/' + tempModified.getFullYear();
HTML +='<div>'+Editor+' ('+Modified+'): '+AdditionalComments+' | </div><br/>';
i++;
});
}
});
}
for more information, refer the below link,
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit sharepoint.stackexchange