SPUpdateMultipleListItems not using defaults.listName?

Mar 6, 2014 at 11:22 AM
Edited Mar 7, 2014 at 11:26 PM
[SPServices 2014.01.min, jQuery 1.10.2.min]

I'm using default to specify a list name to use on all of the calls on this page:
$().SPServices.defaults.listName = "MyList";
On this page I use these functions which should use this default:
  • $().SPServices() - operation: "GetList"
  • $().SPServices.SPUpdateMultipleListItems
  • $().SPServices() - operation: "UpdateListItems"
The call to SPUpdateMultipleListItems keeps on failing, both other calls work with the now defined defaults value.
Reason being that the call to $().SPServices() - operation: "GetListItems" within SPUpdateMultipleListItems fails because the list name default doesn't seem to be used (see line 3448 in jquery.SPServices-2014.01.js).

This is the relevant quote from the request that's being sent bei GetListItems to Lists.asmx: "<listName></listName>"
Once I define the " listName: 'MyList' " in my call to SPUpdateMultipleListItems manually again the same quote is: "<listName>MyList</listName>"

I tried to debug this but my JS skills aren't enough to the bottom of this.
Does SPUpdateMultipleListItems not use the defaults value or could there be some other error?

TL;DR

-- WORKS --
$().SPServices.SPUpdateMultipleListItems({
  listName: "MyList",
  async: false,
  CAMLQuery: "<Query><Where><Gt><FieldRef Name='ID'/><Value Type='Integer'>0</Value></Gt></Where></Query>",
  batchCmd: "Delete",
  completefunc: function(xData, Status) {
    doStuff();
  }
}); 
-- DOES NOT WORK --
$().SPServices.defaults.listName = "MyList";

$().SPServices.SPUpdateMultipleListItems({
  async: false,
  CAMLQuery: "<Query><Where><Gt><FieldRef Name='ID'/><Value Type='Integer'>0</Value></Gt></Where></Query>",
  batchCmd: "Delete",
  completefunc: function(xData, Status) {
    doStuff();
  }
}); 
Mar 7, 2014 at 3:08 PM
I just took a quick look at v2014.1 and your are correct in that this utility does not seem to use globals... Not sure if by design - Marc will need to comment on that...

If you want to include defaults on your own version, you can change line 3429-3437 to include the defaults... That line of code would go from:
 var opt = $.extend({}, {
            webURL: "", // [Optional] URL of the target Web.  If not specified, the current Web is used.
            listName: "", // The list to operate on.
            CAMLQuery: "", // A CAML fragment specifying which items in the list will be selected and updated
            batchCmd: "Update", // The operation to perform. By default, Update.
            valuepairs: [], // Valuepairs for the update in the form [[fieldname1, fieldvalue1], [fieldname2, fieldvalue2]...]
            completefunc: null, // Function to call on completion of rendering the change.
            debug: false // If true, show error messages;if false, run silent
        }, options);
To:
 var opt = $.extend({}, {
            webURL: "", // [Optional] URL of the target Web.  If not specified, the current Web is used.
            listName: "", // The list to operate on.
            CAMLQuery: "", // A CAML fragment specifying which items in the list will be selected and updated
            batchCmd: "Update", // The operation to perform. By default, Update.
            valuepairs: [], // Valuepairs for the update in the form [[fieldname1, fieldvalue1], [fieldname2, fieldvalue2]...]
            completefunc: null, // Function to call on completion of rendering the change.
            debug: false // If true, show error messages;if false, run silent
        }, $.fn.SPServices.defaults, options);
NOte: in your initial post you indicated that you are setting defaults in $.SPServices.defaults, which is not correct... Its actually in $.fn.SPServices.defaults.
Coordinator
Mar 7, 2014 at 7:56 PM
Looks like a bug on my end. I'll add it to the list of fixes for the next release.

M.
Coordinator
Mar 7, 2014 at 7:57 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Mar 7, 2014 at 11:31 PM
ptavares:
Thanks for the hint! I'll make sure to check out your fix. Re: your note - the defaults are indeed being set like I mentioned in my post (I corrected my code a little bit so it's clearer to read) - check out the documentation over here: https://spservices.codeplex.com/wikipage?title=$().SPServices.defaults&referringTitle=Documentation
At least that's what I tried and it worked/didn't work like I described above ;)

sympmarc:
Thanks for your fast answer! I corrected my code a little bit and also just commented on the work item to clarify that.
Mar 8, 2014 at 4:26 AM
Ahh.. Ok.. Now it makes more sense the way you are setting it... in jQuery $() is the same as $.fn (it inherits the same scope)... $. however, is not the same - different scope :-)
Mar 8, 2014 at 5:17 PM
Oh - makes sense. Thanks for mentioning that - still learning the finer lines of JS ;)
Coordinator
Mar 9, 2014 at 3:53 PM
In the short term, you can either patch your copy of SPServices, as Paul suggested, or simply add the listName into each call.

Sorry for the trouble.

M.
Mar 10, 2014 at 10:57 AM
Thanks for the advice on this!
No trouble at all - thanks so much for the effort you're putting into this!