jQuery Library for SharePoint Web Services (SPServices) v0.7.0 Beta 1 Available

Tonight I posted the first (we always hope the only) beta for SPServices v0.7.0. Initially I was calling this release v0.6.3, but when jQuery 1.7 was released and it caused problems with SPServices, I decided to bump the version so that the sevens matched. Get it? 1.7 and v0.7.0? Such are the complex decisions we make about software version numbering. (Those of you who wonder why I still am using sub- version 1.0 numbering – it’s just because I feel like it. No real reason.)

One of the biggest things in this new beta is compatibility with jQuery 1.7. In a previous post, I talked about the fact that the .find("[nodeName='z:row']") syntax no longer worked with jQuery 1.7. This was a real annoyance, but due to some great work by Steve Workman, I think there’s an even better selection method in v0.7.0. Unfortunately, if you’d like to move to jQuery 1.7 in your environment, you’ll have to change the syntax in all of your code as well. What the jQuery team decides to change is out of my hands, of course, so occasionally this sort of thing will happen.

There’s an new function in SPServices called SPFilterNode, which is really quite simple, but it solves the problem, based on Steve’s work.

// This method for finding specific nodes in the returned XML was developed by Steve Workman. See his blog post
// http://www.steveworkman.com/html5-2/javascript/2011/improving-javascript-xml-node-finding-performance-by-2000/
// for performance details.
$.fn.SPFilterNode = function(name) {
  return this.find('*').filter(function() {
    return this.nodeName === name;
  });
};

Here is an example of the syntax for calling this new function:

$(xData.responseXML).SPFilterNode("z:row").each(function() {

There are several benefits to having this function. First, it works in jQuery 1.7 as well as an earlier versions, going back at least to version 1.4.2, which is as far back as I tested. Second, as you can see if you read through Steve’s benchmarking results, it’s very efficient, even more efficient than the .find("[nodeName='z:row']") syntax. Third, if there is a change like this in a future version of jQuery, I can simply replace the function’s workings and all will continue to function well. Note that you only need to use SPFilterNode, and the .find("[nodeName='z:row']") syntax for that matter, when SharePoint’s Web Services return namespaced elements in the XML *and* you want to ensure cross-browser compatibility. If the nodes have names like “item” or “region”, or any other simple name which isn’t preceded with something and a colon, then .find(“item”) or .find(“region”) works fine. Of course, SPFilterNode will also work, but it’s not necessary.

If you are using SPServices and can do some regression testing, I’d certainly appreciate it, as will the other almost 8000 people who have downloaded SPServices v0.6.2 and may want to upgrade. Just be sure that you use the new SPFilterNode function if you are retrieving data from GetListItems with jQuery 1.7 or else it will seem as though you aren’t get anything back from the call.

I’ll publish the rest of the release notes when I release a stable version of v0.7.0, but if you’d like to see what’s in this version, check out the download page. As usual, it’s a mix of bug fixes, performance enhancements, and new features,.

Similar Posts

15 Comments

  1. Hi Marc, Thank you for your time for spending time on this however I got a problem with my sharepoint site, I used your code, and I am not sure, what is the problem in my code, If you will get some time plz have a look at it.

    I am getting an error like jQuery undefined. I used the following code,

    var groupName;

    $().SPServices({ operation: “GetGroupCollectionFromUser”, userLoginName: $().SPServices.SPGetCurrentUser(), async: false, completefunc: function(xData, Status) { alert(xData.responseXML.xml); $(xData.responseXML).SPFilterNode(“[nodeName=Group]”).each(function() {
    groupName = $(this).attr(“Name”); }); } });
    if($.trim(groupName) != ‘Ms g’)
    {
    document.getElementById(‘s4-leftpanel’).style.display = ‘none’;
    }

      1. Thank you very much Marc, After I referenced the latest JQuery library in my site, I got my jquery worked!! Thank you for spending time on this. Any ways fantastic work from you!!

  2. Hi Marc

    Does SPServices.SPGetCurrentUser require specific permissions to run.

    It works for me but when I test with users it returns ‘undefined’

    Regards,
    Dean

  3. $(document).ready(function() {

    alert(“teste”);

    $(“#item”).append(‘Teste’);

    });

    $().SPServices({
    operation: “GetListItems”,
    async: false,
    listName: “testlist”,
    CAMLViewFields: “”,
    completefunc: function (xData, Status) {
    $(xData.responseXML).find(“[nodeName=z:row]”).each(function() {
    var liHtml = “” + $(this).attr(“ows_Title”) + “”;
    $(“#item”).append(liHtml);
    });
    }
    });

    I tryed everything even changing versions on both jquery and SPservices. cant get the query out.
    I have a simple test List with 3 items. with Title field in same website. Im using this code in a CEWP
    The Alert Message shows up, The First Append works. The SPService dont work.

      1. ty for your fast respond,

        I used jquery1.6.2 / .3 still dint work.

        I used SPServices function SPFilterNode instead and still dint work.

        Debuging from Ffox with fire bug.

        I go from “completefunc: function (xData, Status) {” part to Jquery jquery-1.6.4.js file
        To the line with this code :

        if ( document.addEventListener ) {
        DOMContentLoaded = function() {
        document.removeEventListener( “DOMContentLoaded”, DOMContentLoaded, false );
        jQuery.ready();
        };

        And simply stops at “jQuery.ready();”

        1. $(document).ready(function() {

          alert(“test 1”);

          $(“#item”).append(‘Teste’);

          $().SPServices({
          operation: “GetListItems”,
          async: false,
          webURL: “http://tmn-pm.telecom.pt/encarteiramento”,
          listName: “testlist”,
          CAMLViewFields: “”,
          completefunc: function (xData, Status) {
          alert(“test 2”);
          $(xData.responseXML).SPFilterNode(“z:row”).each(function() {
          var liHtml = “” + $(this).attr(“ows_Title”) + “”;
          $(“#item”).append(liHtml);
          });
          }
          });

          });

          Copy/Pasting the current code in CEWP, I also notice that the first Alert fires, and the secand alert dont. So he dont even reach the $(xData.responseXML).SPFilterNode function.

          1. after 2 days of frustration I find out the solution.

            I had this :

            src=”/…/SiteAssets/jquery.SPServices-0.6.2.js” type=”text/javascript”
            src=”/…/SiteAssets/jquery-1.8.2.min.js” type=”text/javascript”

            and jquery need to come first -.- so stupid of me :S

            src=”/…/SiteAssets/jquery-1.8.2.min.js” type=”text/javascript”
            src=”/…/SiteAssets/jquery.SPServices-0.6.2.js” type=”text/javascript”

  4. Hi Marc,

    I’m am trying to determine a list count based on connected user :

    var $jq2 = jQuery.noConflict(true);

    var connectedUser = $jq2().SPServices.SPGetCurrentUser({
    fieldName: “Name”,
    debug: false
    });
    var itemCount=0;
    var queryText = “”+connectedUser+””;
    alert(queryText);
    $jq2().SPServices({

    operation: “GetListItems”,
    listName: “Demandes Newsletter”,
    async: false,

    CAMLQuery: queryText,

    completefunc: function (xData, status) {

    alert(xData.responseXML.xml);
    itemCount = $jq2(xData.responseXML.xml).find(“rs\\:data, data”).attr(“ItemCount”);
    alert(itemCount);

    }
    });

    but when running this code, i had xData.responseXML.xml is undefined.

    Regards,
    Oumaima

    1. Oumaima:

      You don’t need the .xml. You should look at the examples on the SPServices site on Codeplex in the documentation. There is also a lot of code posted by people in the discussions.

      M.

Leave a Reply to Marc Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.