This project has moved and is read-only. For the latest updates, please go here.

UpdateListItems Error

Jan 2, 2013 at 2:37 PM

Hi All, I'm upgrading my platform to run jQuery 1.8.3 and SPServices 0.7.2.  With these files in place, I get an error each time I attempt to run the UpdateListItems operation.  I do not get the error using jQuery 1.7.2 and SPServices 0.7.1a.   I've attempted to debug as much as I can but can't find where the problem lies.  The code I'm running is basically....

//Append the Document Approvals with a placeholder record for the new document
  var lngDocID = 1151;
       operation: "UpdateListItems",
       async: false,
       batchCmd: "New",
       listName: "Document Approvals",
       valuepairs: [["TaskOrderDocID", lngDocID]],
       completefunc: null

I've also tried a variant of this operation as....

  var lngDocID = 1151;
$().SPServices({ operation: "UpdateListItems", async: false, listName: "Document Approvals", updates: "<Batch OnError='Continue' PreCalc='TRUE'>" + "<Method ID='1' Cmd='New'>" + "<Field Name='TaskOrderDocID'>" + lngDocID + "</Field>" + "</Method>" + "</Batch>", completefunc: null });

In either case, jQuery throws an error at line 7987 and just says "Object Expected."  I can't figure out which object it's looking for.  Now, with that, it appears the Update action does occur in both instances--the new record appears in the list as it should.  I can't figure out why jQuery is throwing an error.  Has anyone experienced this with the latest versions? Do you have any ideas on what might be causing it? Thanks!



Jan 2, 2013 at 6:03 PM
Edited Jan 2, 2013 at 6:03 PM

Drop your completefunc: null reference...  I'm not sure if there is a check for it being a function or not in either library and invoking null will definitely throw an error.


Jan 2, 2013 at 6:17 PM

I appreciate that tip.  I updated my code but still get the same result in the same line of the jQuery module.  jQuery is the one throwing the error, not SPServices.


Jan 2, 2013 at 8:19 PM

The problem from what I've found looks to be a bug in SPServices 0.7.2.  I've found this on line 1206:

opt.completefunc(cachedXML, status);				// When the call is complete, do this

The error you are getting is because you can't invoke null...  The line above does that blindly without checking the actual property for anything...  I modded line 1206 to this and it works like a charm.

if ( $.isFunction( opt.completefunc ) ) {
	opt.completefunc( cachedXML, status );				// When the call is complete, do this

Let me know if that fixes you up...


Jan 2, 2013 at 8:25 PM
Edited Jan 2, 2013 at 8:26 PM

Thinking about this a bit more, an added safety benefit would be to wrap any completefunc calls with $.isFunction.  The function appears lightweight, but you always have to weigh the benefits...


Jan 3, 2013 at 2:11 PM

I don't know how you found that but it's a good one!  I verified your point by adding a completefunc argument to my code just to pass something (without modifying the SPServices 0.7.2 file).  It works fine with a completefunc argument.  However, when the completefunc argument is null or is not present at all (which is then null by default), I get the error in jQuery.  Next, I removed the completefunc argument from my code and modified the SPServices 0.7.2 file as you mentioned.  All worked well that way too.  Oh, I also noticed that same command is at line 1211 so I modified it there as well.

Marc, I'm sure you'll come across this thread in due time and see what we're talking about here.  It appears that jQuery 1.8.x is handling something different here than it did previously.  Matthew's suggestion above appears to overcome the issue when users don't include a completefunc argument.  I haven't experienced the issue with any other operations within SPServices using v0.7.2 with jQuery 1.8.x.

Now, all that being said, if I were practicing good coding protocol in the first place, I would have put something in the completefunc argument as a way to validate the results and would never have come across this issue.  :P



Jan 3, 2013 at 4:50 PM

I'm glad you were able to repro.  During your upgrade, you can replace the completfunc: null reference and use $.noop instead.  That should allow SPServices to fire without error.  I'll ping Marc on the Twitterz and bring this to his attention.


Jan 3, 2013 at 5:16 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.