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,.




11 comments
2 pings
Skip to comment form ↓
Theater Balcony
December 6, 2011 at 2:51 am (UTC -4) Link to this comment
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’;
}
Marc
December 6, 2011 at 7:13 am (UTC -4) Link to this comment
Theater:
Your error indicates that you don’t have a valid reference to the jQuery library.
M.
Theater Balcony
December 8, 2011 at 8:31 am (UTC -4) Link to this comment
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!!
Dean
February 24, 2012 at 7:44 am (UTC -4) Link to this comment
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
Marc
February 24, 2012 at 3:10 pm (UTC -4) Link to this comment
Dean:
It gets the info from _layouts/userdisp.aspx. Every user should be able to view their own version of that page.
M.
Luis Teixeira
September 25, 2012 at 7:48 am (UTC -4) Link to this comment
$(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.
Marc
September 25, 2012 at 7:56 am (UTC -4) Link to this comment
Luis:
If you’re using jQuery 1.7+,
.find("[nodeName=z:row]")won’t work. Use the SPServices function SPFilterNode instead.M.
Luis Teixeira
September 25, 2012 at 10:05 am (UTC -4) Link to this comment
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();”
Luis Teixeira
September 25, 2012 at 10:12 am (UTC -4) Link to this comment
$(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.
Luis Teixeira
September 25, 2012 at 10:29 am (UTC -4) Link to this comment
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”
Marc
September 25, 2012 at 6:41 pm (UTC -4) Link to this comment
Luis:
That’ll do it!
M.
Sharepoint Updates November-24-2011 | SDavara's Sharepoint Knowledge Center
November 25, 2011 at 1:28 am (UTC -4) Link to this comment
[...] English jQuery Library for SharePoint Web Services (SPServices) v0.7.0 Beta 1 Available [...]
Problem with jQuery 1.7+ and SPServices » Marc D Anderson's Blog
March 27, 2012 at 9:00 am (UTC -4) Link to this comment
[...] issue is resolved in v0.7.0+. See this post for more details, including the SPFilterNode function. [...]