Using SPServices & jQuery to Clone a Parent Item and All Its Children: Comments on Mark Rackley’s Post

Mark Rackley (@mrackley) is definitely earning the salary I’m paying him as the Marketing Manager for SPServices.  (Yes, that salary is zero.) He posted another great article about Using SPServices & jQuery to Clone a Parent Item and All its Children today, and I wanted to point out a few things about it. I’m not dissing Mark in any way: his article is excellent. There are just a few things I’d suggest. ;+)

  • On Mark’s “batches’ comment, I haven’t done testing to determine the optimal numbers there, either. However, the constraints are very different, since you are asking the client machines to do the processing. The important thing is to know what the *worst* configuration might be in your user base and consider it for testing.
  • There’s a function in SPServices called $().SPServices.SPGetQueryString that will do the Query String parsing for you.
  • Always use the minified version of your jQuery libraries if you can; they are “squished” to send the fewest bytes down the wire. e.g., jquery.SPServices-0.5.8.min.js instead of jquery.SPServices-0.5.8.js.
  • I think it’s a bug in the Lists Web Service, but even when you specify just the Title in the CAMLViewFields as Mark has, you still get all of the mandatory columns, *even* if you specify IncludeMandatoryColumns=”false” in the queryOptions. It’s usually no big deal, but it makes calls to GetListItems where there are a lot of items returned less efficient than you might expect.
  • JavaScript gives you a little shorthand for adding text to a string. Instead of this:
                updateXML = updateXML + "<Method ID='" + index++ + "' Cmd='New'>" +
                        "<Field Name='Title' Type='String'>" + title  +  "</Field>" +
                        "<Field Name='Entry_x0020_Date' Type='Date'>" + entryDate +  "</Field>" +
                        "<Field Name='Hours' Type='Number'>" + hours +  "</Field>" +
                        "<Field Name='IssueID' Type='Number'>" + newParentID +  "</Field>" +
                        "</Method>";

you can do this:

                updateXML += "<Method ID='" + index++ + "' Cmd='New'>" +
                        "<Field Name='Title' Type='String'>" + title  +  "</Field>" +
                        "<Field Name='Entry_x0020_Date' Type='Date'>" + entryDate +  "</Field>" +
                        "<Field Name='Hours' Type='Number'>" + hours +  "</Field>" +
                        "<Field Name='IssueID' Type='Number'>" + newParentID +  "</Field>" +
                        "</Method>";

I know that this may seem nitpicky, but it’s a nice little shorthand and it sometimes helps (at least it helps me) to see where I’m adding to strings versus setting them to a new value.

  • There’s a little typo at the end. Spaces in the middle of the internal names of columns are represented by “_x0020”. Remember your ASCII character codes? Almost any character which isn’t a letter or number will be represented this way, using the hexadecimal ASCII value. Here are a few examples: 
    • ( is _x0028_ and ) is _x0029_
    • The underscore ‘_’ is _x005f_
    • etc.

Thanks, Mark for a great article!

Similar Posts

Leave a 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.