$().SPServices.SPUpdateMultipleListItems

Dec 7, 2010 at 6:24 PM

I know I'm beating you up in multiple places, but I'd rather the discussion be here.  I have this function:

function deleteItems(listName, strColumnName) {
	alert("Delete Items called: " + listName + " " + strColumnName);
	//CAML for item query
	var query = "<Query><Where><Eq><FieldRef Name='" + strColumnName + "' /><Value Type='Text'>" + projID + "</Value></Eq></Where></Query>";
	alert(query);
	$().SPServices.SPUpdateMultipleListItems({
		listName: listName,
		CAMLQuery: query,
		batchCmd: "Delete",
		completefunc: function(xData, Status) {
			alert(Status);
			resetPage(Status);
		} //completefunc
	}); //SPServices-UpdateMultiItems
} //deleteItems func

I'm getting the columnName and listName from other functions and this all works except for Document Libraries.  I was wondering if there's something I've missed or a bug.  

Dec 7, 2010 at 7:37 PM

Is this a case of needing to have the actual fileref to delete it. I did not think that a direct delete would work because of the way it stores the data for doc libraries.

Example Code

string xml = "<Batch OnError='Continue'><Method ID='1' Cmd='Delete'><Field Name='ID'>1</Field >";
      xml += "<Field Name='FileRef'>PathToFile</Field>";
      xml += "</Method></Batch>";

Dec 7, 2010 at 10:34 PM

I'm going to hard code your XML query and see if the test docs delete.  Your answer seems like the root cause of this issue.

I'll let you guys know!

Dec 8, 2010 at 2:02 PM

No matter what I try, $().SPServices.SPUpdateMultipleListItems doesn't seem to work with Document Libraries. I hardcoded the query above from SPEvilGenius and it's still not working. I suppose I could do a call to UpdateItem when I find a doc library,

but that's not as effective as using the MultiUpdate function.

Coordinator
Dec 8, 2010 at 2:04 PM

Sorry to have not replied to this; it's been a busy stretch.

I'll look at this, but in the meantime, I'm going to add a note to the documentation that SPUpdateMultipleListItems only works for lists right now.

M.

Coordinator
Dec 8, 2010 at 2:09 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Dec 8, 2010 at 2:16 PM
Edited Dec 8, 2010 at 3:55 PM

I guess it helps to really read what you are doing sometimes! It looks like you are trying to delete multiple files from a document library. The code I posted was for a single file and I have seen this work. I think that for doc libs, you have to first get all of the files from a getitems query and then loop through those items using the code to delete it in the completefunc. I am just not sure you can do a bulk delete in one shot on doc libs.

Dec 8, 2010 at 7:26 PM
spevilgenius wrote:

I guess it helps to really read what you are doing sometimes! It looks like you are trying to delete multiple files from a document library. The code I posted was for a single file and I have seen this work. I think that for doc libs, you have to first get all of the files from a getitems query and then loop through those items using the code to delete it in the completefunc. I am just not sure you can do a bulk delete in one shot on doc libs.

If it can be done, I'm sure Marc will plow the way!  Thanks guys for helping me out!

Muchas gracias,

Matt

Coordinator
Apr 13, 2011 at 4:39 AM

Sorry about the delay, gents, but I've got a fix in v0.6.1ALPHA4. Posting now, if any of you would like to test...

M.

May 5, 2011 at 10:00 PM
Edited May 5, 2011 at 10:30 PM

Just tested this on a document library and as always, works like a charm.  However the completefunc is acting funky.  Here's a little chunk of code:

 

<script type="text/javascript" src="/Scripts/jquery.min.js"></script>
<script type="text/javascript" src="/Scripts/jquery.SPServices-0.6.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	$("input[name='Armageddon']").click(function() {
		DeleteDocs();
	});
});
function DeleteDocs() {
	var relatedID = $("input[name='relatedID']").val();
	alert(relatedID);
	
	$().SPServices.SPUpdateMultipleListItems({
  		listName: "Child Docs",
  		CAMLQuery: "<Query><Where><Eq><FieldRef Name='ParentID'/><Value Type='Lookup'>" + relatedID + "</Value></Eq></Where></Query>",
  		batchCmd: "Delete",
        	completefunc: function(xData, Status) {
          		console.log("Status: ", Status);
          		console.log("sexyData: ", xData.responseXML.xml);
        	} //completefunc
   	}); 
};
</script>

 

Now when I delete one or mulitple documents, I get a log in the console as: Status: undefined but nothing for xData.  I remember there being issues with the completefunc of this call, I wonder now that it's compatible with documents, if that has thrown something off.

Thanks for your efforts in making this library awesome!

I should also note the test above was done using jQuery v1.4.4 and SPServices v0.6.1.  I'll test with the latest release of jQuery and see if that provides a different result set.

Cheers,

Matt