Feature needed: GetVersionCollection

Dec 28, 2011 at 2:12 AM

Hi Marc,

I would appreciate if a feature to retrieve all the version history of a SharePoint List could be added as mention in my post (http://sharepoint.stackexchange.com/questions/23591/displaying-the-item-version-history-programmatically-using-javascript).

Thank you.

Coordinator
Dec 28, 2011 at 4:09 AM
Larry:

Have you looked at GetVersions? http://spservices.codeplex.com/wikipage?title=Versions

M.
Dec 28, 2011 at 4:30 AM

Hi Marc,

I looked at the GetVersions and also Danny from the post mention above provided the following code:

 

$().SPServices({
    operation: "GetVersions",
    fileName: "http://spsrv2010/DocLib/file.txt",
    completefunc: function (xData, Status) {
        // Do other stuff...
    }
});

 

and I found that there is this option - filename.

As I am dealing with SharePoint List's item, I doubt there is filename for SharePoint List. Also, Danny mention that for a standard list, I will need to use the GetVersionCollection method of the Lists web service.


Currently, I have no ideas on how to retrieve the version history of a particular item inside a SharePoint List (since I have been searching around for a solution).

I would appreciate if you can show me a simple code example of getting the version history of a item in a SharePoint List. (Lets assume that the name of the SharePoint List is "Equipments" and I wish to retrieve the version history of the item "Cocoa Bean Vibratory Feeder")

Thank you.

Coordinator
Dec 29, 2011 at 5:53 AM

Larry:

At some point in the past, GetVersions worked for lists as well as Document Libraries. I found this MSDN post which makes it clear that this is no longer the case. The notation in the post did work in the past.

I took a look at the GetVersionCollection operation for you and added it into SPServices v0.7.1ALPHA1. This is an odd operation, to me. You have to provide the list ID (or name), item ID, and a column name. The operation then gives you back the date/time stamps for when that particular column was changed. I played around with it a bit, but I'm still not certain how useful it is. However, I did want to add it into SPServices for completeness, if nothing else. Take a look and let me know if it helps at all; my guess is that it won't do what you need.

M.

 

Dec 30, 2011 at 5:09 AM

Thanks Marc,

Tried your SPServices v0.7.1ALPHA1. The result was good but I still trying to retrieve the results. Below is my code (draft & buggy) for your advice.

Name of my List: tester. Name of the Field (Column Header): Information.

		function VersionShow(){
			$().SPServices({
			  debug: true,
			  operation: "GetVersionCollection",
			  async: false,
			  strlistID: "tester",
				strlistItemID: 1,
				strFieldName: "Information",
			    completefunc: function (xData, Status) {
			    	console.log(xData.responseText);
			      	//printObject(xData);
			      	var i=0;
			      	console.log(i);
				      $(xData.responseText).find("[nodeName='Version']").each(function() {
				        	i++;
				        	console.log(i);
				      		console.log( "Name: " + $(this).attr("Version_x0020_Information") );
				      });
     	
			    }
			  });

		}

By the way, is it possible not to identify the field name - meaning that SPServices will retrieve all the versioning (of any changes to any field)?

Thank you and wish you a Happy New Year.

 

 

Coordinator
Dec 30, 2011 at 1:58 PM

Larry:

I tried omitting the field name, and just got an error, so I believe it's required. As you probably noticed, the documentation for this operation is minimal, at best.

This works for me, though I tested with my columns "Title" and "Lead_x0020_Source". The operation requires the StaticName for the column rather than the DisplayName, e.g., "Lead_x0020_Source" rather than "Lead Source".

$().SPServices({
  operation: "GetVersionCollection",
  async: false,
  strlistID: "tester",
  strlistItemID: 1,
  strFieldName: "Information",
  completefunc: function (xData, Status) {
    $(xData.responseText).find("Version").each(function(i) {
      console.log("Name: " + $(this).attr("Information") + " Modified: " + $(this).attr("Modified"));
    });  
  }
});

M.

Jan 3, 2012 at 12:58 AM

Thanks Marc.

Mar 15, 2012 at 8:43 PM

Thanks Marc. After reading the docs my conclusion yesterday was that you could only retrieve versions in document libraries (as I wrote here yesterday: http://sharepoint.stackexchange.com/questions/31513/display-task-historic-data/)

Fortunately today I read Larry's review of the alpha version and it drove me here (so thanks Larry too).

Coordinator
Mar 19, 2012 at 4:17 PM

Christophe:

Do you find that GetVersionCollection does what you need? I find it an odd operation.

M.

Mar 19, 2012 at 6:23 PM

I haven't had a chance to try it yet... For our specific scenario, we chose another way, using joined lists.

Nov 18 at 6:30 PM
Marc, it appears the code above only works for 1 item in a list at a time. I need to get the changes for ALL list items, but only for 3 specific fields? I don't really care about any changes except to these 3 specific fields. I would like it to show me the following info in a display or better yet, in an excel worksheet:
ItemID, VersionNumber, ModifiedDate, ModifiedBy, Field1, Field2, Field3

I am inserting this into a CEWP because at this point, it is the only thing I really know how to do (I was lucky to have been able to download SPServices, company policy). If there is a better way to go about this, please tell me. I have been trying to figure this out for waaaaayyyyy too long now.

Thanks for any help you can provide to me!