Pergunta

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?

Foi útil?

Solução

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,

  1. http://mundrisoft.com/tech-bytes/how-to-read-the-version-history-of-multiline-column-from-list-in-office-365-sharepoint-2013-page/

  2. https://social.technet.microsoft.com/wiki/contents/articles/29559.sharepoint-hosted-apps-working-with-version-history-of-multiple-lines-of-text-column.aspx

  3. https://stackoverflow.com/questions/24423657/sharepoint-2013-get-splistitem-versions-via-rest

Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange
scroll top